﻿// ## 2024/02/04 # 黑店小小二 # 添加is_neighbor_force函数 ##
// ## 2023/11/24 # 黑店小小二 # 增加兼容自动内政的舌战函数 ##
// ## 2022/09/1 # 铃 # 优化人口增长的算法 ##
// ## 2022/04/29 # 铃 # 为新人口系统做适配 ##
// ## 2022/02/17 # 江东新风 # 部分人口函数移入 ##
// ## 2021/10/29 # 江东新风 # 结构体存储调用方式改进 ##
// ## 2021/10/24 # 江东新风 # 将pk::add_troops换成ch::add_troops以修正显示错误 ##
// ## 2021/10/24 # 江东新风 # get_stronghold_list改为get_base_list ##
// ## 2021/10/10 # 江东新风 # 治安增减的非城市据点函数 ##
// ## 2021/03/02 # 江东新风 # 特殊地名重建通用函数，cpp里调用kill_building都需要加上 ##
// ## 2021/02/04 # 江东新风 # 添加设置武器及马匹参数的函数 ##
// ## 2021/01/31 # 江东新风 # rand函数使用错误修复 ##
// ## 2021/01/23 # 江东新风 # get_order_change building版 ##
// ## 2021/01/14 # 江东新风 # 关掉trace ##
// ## 2021/01/13 # 江东新风 # 修复特殊设施闪退bug2 ##
// ## 2021/01/12 # 江东新风 # 修复特殊设施闪退bug ##
// ## 2021/01/11 # 江东新风 # 将特殊设施不被破坏的相关函数移入此处 ##
// ## 2021/01/06 # 江东新风 # 新增get_weapon_name函数 ##
// ## 2021/01/02 # 江东新风 # 新增rand_bool_1000和rand_bool_10000 ##
// ## 2020/12/23 # 江东新风 # 身份中文化 ##
// ## 2020/12/13 # 江东新风 # 添加获取城市港关list的函数 ##
// ## 2020/12/12 # 江东新风 # 修正参数类型错误 ##
// ## 2020/11/30 # 江东新风 # 新函数 get_force_food,get_force_gold, get_force_weapon ##
// ## 2020/10/27 # 江东新风 # 新函数 who_has_skill ##
// ## 2020/10/23 # 氕氘氚 # 取消全部ch::has_skill的组合特技判断 ##
// ## 2020/10/04 # 氕氘氚 # 再次修复宝物特技不生效的bug ##
// ## 2020/10/03 # 氕氘氚 # 修复add_tp在扣技巧时也翻倍的bug ##
// ## 2020/09/23 # 江东新风 # utf8版本u8debug ##
// ## 2020/09/21 # 氕氘氚 #修改函数has_skill, 武将行动时也生效##
// ## 2020/09/15 # 江东新风 #新增针对部队成员计算特技的has_skill版本，用于修复163移动力显示异常的bug##
// ## 2020/08/29 # 氕氘氚 #  添加函数debug
// ## 2020/08/21 # 氕氘氚 #  添加函数set_status
// ## 2020/08/18 # 氕氘氚 # 添加函数get_best_member_stat，添加get_order_change、add_public_order，特技法治影响治安下降 ##

const bool DEBUG_MODE = true;
const int DEBUG_LEVEL = -1;

namespace ch
{
	//////////////////////////////基础底层函数及math//////////////////////////////////////////
	//  打印調試信息
	void trace(string trace_info)
	{
		if (DEBUG_MODE)
			pk::trace(trace_info);
	}
	void debug(string debug_info)
	{
		if (0 > DEBUG_LEVEL)
			pk::trace("[debug] " + debug_info);
	}
	void debug(int level, string debug_info)
	{
		if (level > DEBUG_LEVEL)
			pk::trace("[debug] " + debug_info);
	}

	//  打印調試信息u8版本
	void u8trace(string trace_info)
	{
		if (DEBUG_MODE)
			pk::trace(trace_info);
	}
	void u8debug(string debug_info)
	{
		if (0 > DEBUG_LEVEL)
			pk::trace("[debug] " + debug_info);
	}
	void u8debug(int level, string debug_info)
	{
		if (level > DEBUG_LEVEL)
			pk::trace("[debug] " + debug_info);
	}

	int randint(int start, int end)
	{
		return start + pk::rand(end - start + 1);
	}

	float randfloat(float start, float end)
	{
		int s = int(start * 100.f), e = int(end * 100.f);
		return (s + pk::rand(e - s + 1)) / 100.f;
	}

	bool rand_bool_1000(int rate)
	{
		rate = pk::max(0, pk::min(999, rate));
		if (int(pk::rand(1000)) < rate)
			return true;
		return false;
	}

	bool rand_bool_10000(int rate)
	{
		rate = pk::max(0, pk::min(9999, rate));
		if (int(pk::rand(10000)) < rate)
			return true;
		return false;
	}

	//  与0比較，至少为0
	int minZero(int value)
	{
		return pk::max(0, value);
	}

	//  设置上下限
	int inRange(int value, int min, int max)
	{
		return pk::max(min, pk::min(max, value));
	}
	//  设置上下限
	float inRange(float value, float min, float max)
	{
		return pk::max(min, pk::min(max, value));
	}

	uint32 set_bit(uint32 i, int pos, bool value)
	{
		//uint32 t = value ? 1 : 0;
		//i |= t << pos;
		//return i;
		return pk::set_bit(i, pos, value);
	}

	bool test_bit(uint32 i, int pos)
	{
		return pk::test_bit(i, pos);// (((i << (31 - pos)) >> 31) == 1);
	}

	void shuffle(array<int>& arr)
	{
		int n = arr.length;
		for (int i = 0; i < n; i++)
		{
			int j = pk::rand(n); // 不确定随机值是否固定
			int temp = arr[i];
			arr[i] = arr[j];
			arr[j] = temp;
		}
	}

	float get_modify_rate(float rate)
	{
		if (rate < 1.f)
			return rate;
		else
			return sqrt(rate);
	}

	array<int> get_x_rand_int(int min, int max, int num)
	{
		array<int> temp;
		// temp.clear();
		int length = max - min;
		if (num > length)
			return temp;
		for (int i = min; i < max; ++i)
		{
			temp.insertLast(i);
		}

		shuffle(temp);
		array<int> arr;
		for (int i = 0; i < num; ++i)
		{
			arr.insertLast(temp[i]);
		}
		return arr;
	}

	// 在给定范围内生成num个随机数，排除ignore数组里的随机数
	array<int> get_x_rand_int(int min, int max, int num, array<int> ignore)
	{
		array<int> temp;
		// temp.clear();
		int length = max - min;
		if (num > length)
			return temp;
		for (int i = min; i < max; ++i)
		{
			temp.insertLast(i);
		}

		shuffle(temp);
		array<int> arr;
		int count = 0;
		for (int i = min; i < max; ++i)
		{
			if (ignore.find(temp[i]) > 0)
				continue;
			arr.insertLast(temp[i]);
			count += 1;
			if (count == num)
				break;
		}
		return arr;
	}

	void sort_arr(array<int>& inout arr, array<int>& inout index)
	{
		// 冒泡排序,每一趟找出最大的,总共比较次数为arr.length-1次,每次的比较次数为arr.length-1次，依次递减
		int len = arr.length;
		for (int k = 0; k < len - 1; k++)
		{
			for (int m = 0; m < len - k - 1; m++)
			{
				if (arr[m] < arr[m + 1])
				{
					int val = arr[m];
					arr[m] = arr[m + 1];
					arr[m + 1] = val;
					val = index[m];
					index[m] = index[m + 1];
					index[m + 1] = val;
				}
			}
		}
	}

	/////////////////////////获取对应结构体/////////////////////////

	void write_multibyte(pk::s11writer@ w, uint count)
	{
		for (uint i = 0; i < count; ++i)
			w.writeUInt8(0);
	}

	void read_multibyte(pk::s11reader@ r, uint count)
	{
		for (uint i = 0; i < count; ++i)
			r.readUInt8();
	}

	void write_multibyte(file@ f, uint count)
	{
		for (uint i = 0; i < count; ++i)
			f.writeUInt8(0);
	}

	void read_multibyte(file@ f, uint count)
	{
		for (uint i = 0; i < count; ++i)
			f.readUInt8();
	}

	BaseInfo @ get_base_p(int base_id)
	{
		if (pk::is_valid_base_id(base_id))
			return base_ex[base_id];
		else
			return null;
	}

	//自动内政获取函数，考虑到以后可能存在的建筑结构体，所以没有用building_p
	BuildingInfo2 @ get_baseIA(int base_id)
	{
		if (pk::is_valid_base_id(base_id))
			return  base_ex[base_id].IA_info;
		else
			return null;
	}

	personinfo @ get_person_p(int person_id)
	{
		if (pk::is_valid_person_id(person_id))
			return person_ex[person_id];
		else
			return null;
	}

	unitinfo @ get_unit_p(int unit_id)
	{
		if (pk::is_valid_unit_id(unit_id))
			return unit_ex[unit_id];
		else
			return null;
	}

	forceinfo @ get_force_p(int force_id)
	{
		if (pk::is_valid_force_id(force_id))
			return force_ex[force_id];
		else
			return null;
	}

	specialinfo @ get_spec_p(int spec_id)
	{
		if (ch::is_valid_spec_id(spec_id))
			return special_ex[spec_id];
		else
			return null;
	}

	settinginfo @ get_set_p(int setting_id)
	{
		if (ch::is_valid_setting_id(setting_id))
			return setting_ex[setting_id];
		else
			return null;
	}

	autoarmyinfo @ get_autoarmy_p(int autoarmy_id)
	{
		if (ch::is_valid_autoarmy_id(autoarmy_id))
			return autoarmy_ex[autoarmy_id];
		else
			return null;
	}

	////////////////////////////has_skill函数扩展/////////////////////////////
	bool has_skill(pk::person @person, int skill_id)
	{
		return pk::has_skill(person, skill_id);
	}

	// 新增针对部队成员计算特技的has_skill版本，用于修复163移动力显示异常的bug
	bool has_skill(const pk::detail::arrayptr<pk::person @>& in member, int skill_id)
	{
		return pk::has_skill(member, skill_id);
	}

	bool has_skill(const array<pk::person @>& member, int skill_id)
	{
		return pk::has_skill(member, skill_id);
	}

	bool has_skill(pk::unit @unit, int skill_id)
	{
		// pk::trace(pk::format("开始判断部队的特技{}持有与否",skill_id));
		if (unit is null)
		{
			// pk::trace("部队不存在");
			return false;
		}
		return unit.has_skill(skill_id); // 因为unit.has_skill调用了4895c0,所以不需要改
	}

	bool has_skill(pk::list<pk::person @> list, int skill_id)
	{
		for (int i = 0; i < list.count; i++)
		{
			pk::person @person = list[i];
			if (pk::is_alive(person) and pk::has_skill(person, skill_id))
				return true;
		}
		return false;
	}
	/**
	 * @param only_not_absent: 只在武将空閑时生效
	 */
	bool has_skill(pk::building @building, int skill_id, bool only_not_absent = false)
	{
		if (building.facility > 2)
			return false;
		auto defender_list = pk::get_person_list(building, pk::mibun_flags(身份_君主, 身份_都督, 身份_太守, 身份_一般));
		if (defender_list.count > 0)
		{
			for (int i = 0; i < defender_list.count; i++)
			{
				pk::person @defender = defender_list[i];
				if ((!only_not_absent) or (!pk::is_unitize(defender) and !pk::is_absent(defender)))
				{
					if (pk::has_skill(defender, skill_id))
						return true;
				}
			}
		}
		return false;
	}

	bool has_skill(pk::force @force, int skill_id)
	{
		if (!pk::is_alive(force))
			return false;
		auto person_list = pk::list_to_array(pk::get_person_list(force, pk::mibun_flags(身份_君主, 身份_都督, 身份_太守, 身份_一般)));
		if (person_list.length > 0)
		{
			for (int i = 0; i < int(person_list.length); i++)
			{
				pk::person @person = person_list[i];
				if (pk::has_skill(person, skill_id))
					return true;
			}
		}
		return false;
	}

	pk::bool_bool has_skill(pk::building @building, int skill_id0, int skill_id1)
	{
		if (building.facility > 2)
			return pk::bool_bool(false, false);
		auto defender_list = pk::get_person_list(building, pk::mibun_flags(身份_君主, 身份_都督, 身份_太守, 身份_一般));
		if (defender_list.count > 0)
		{
			bool has_skill0 = false;
			bool has_skill1 = false;
			for (int i = 0; i < defender_list.count; i++)
			{
				pk::person @defender = defender_list[i];

				if (!has_skill0 and pk::has_skill(defender, skill_id0))
					has_skill0 = true;

				if (!has_skill1 and pk::has_skill(defender, skill_id1))
					has_skill1 = true;

				if (has_skill0 and has_skill1)
					break;
			}
			return pk::bool_bool(has_skill0, has_skill1);
		}
		return pk::bool_bool(false, false);
	}

	int who_has_skill(pk::unit @unit, int skill_id)
	{
		if (unit is null)
			return -1;
		if (skill_id < 0 || skill_id > 特技_末)
			return -1;
		if (skill_id <= 特技_末)
		{
			for (int m = 0; m < 3; m++)
			{
				if (pk::is_valid_person_id(unit.member[m]))
				{
					pk::person @member_t = pk::get_person(unit.member[m]); // 隊伍中的武將
					if (member_t is null || !pk::is_alive(member_t))
						continue;
					if (has_skill(member_t, skill_id))
						return unit.member[m];
				}
			}
		}
		return -1;
	}

	int who_has_skill(pk::building @building, int skill_id, bool only_not_absent = false)
	{
		if (building.get_id() > 87)
			return -1;
		auto defender_list = pk::list_to_array(pk::get_person_list(building, pk::mibun_flags(身份_君主, 身份_都督, 身份_太守, 身份_一般)));
		if (defender_list.length > 0)
		{
			for (int i = 0; i < int(defender_list.length); i++)
			{
				pk::person @defender = defender_list[i];
				if ((!only_not_absent) or (!pk::is_unitize(defender) and !pk::is_absent(defender)))
				{
					if (pk::has_skill(defender, skill_id))
						return defender.get_id();
				}
			}
		}
		return -1;
	}

	int get_best_member_stat(pk::unit @unit, int stat_type)
	{
		return pk::get_best_member_stat(unit, stat_type);
	}
	int get_best_member_stat(pk::unit @unit, int skill_id, int stat_type)
	{
		return pk::get_best_member_stat(unit, skill_id, stat_type);
	}

	pk::person @get_best_stat_member(pk::building @src, int stat_type)
	{
		pk::list<pk::person @> list = pk::get_person_list(src, pk::mibun_flags(身份_君主, 身份_都督, 身份_太守, 身份_一般));
		return get_best_stat_member(list, stat_type);
	}

	pk::person @get_best_stat_member(pk::list<pk::person @> list, int stat_type)
	{
		if (list.count == 0)
			return null;
		int best_stat = 0;
		pk::person @best_member;
		for (int i = 0; i < list.count; ++i)
		{
			if (int(list[i].stat[stat_type]) > best_stat)
			{
				best_stat = list[i].stat[stat_type];
				@best_member = @list[i];
			}
		}
		return best_member;
	}

	int get_best_member_stat(pk::list<pk::person @> list, int stat_type)
	{
		if (list.count == 0)
			return -1;
		int best_stat = 0;
		for (int i = 0; i < list.count; ++i)
		{
			if (int(list[i].stat[stat_type]) > best_stat)
				best_stat = list[i].stat[stat_type];
		}
		return best_stat;
	}

	int get_best_member_stat(pk::list<pk::person @> list, int skill_id, int stat_type)
	{
		if (list.count == 0)
			return -1;
		int best_stat = 0;
		for (int i = 0; i < list.count; ++i)
		{
			if (has_skill(list[i], skill_id))
			{
				if (int(list[i].stat[stat_type]) > best_stat)
					best_stat = list[i].stat[stat_type];
			}
		}
		return best_stat;
	}

	int get_public_order(int base_id)
	{
		if (pk::is_valid_base_id(base_id))
		{
			if (base_id < 城市_末)
				return pk::get_city(base_id).public_order;
			else
				return ch::get_base_p(base_id).public_order;
		}
		return 0;
	}

	int get_order_change(pk::city @city, int value, bool skill_effect = true)
	{
		if (value == 0)
			return 0;
		else if (value < 0)
		{

			if (skill_effect and has_skill(pk::city_to_building(city), 特技_法治))
				value = int(value * pk::core::skill_constant_value(特技_法治) / 100.f);
		}
		return value;
	}

	int get_order_change(pk::building @building, int value, bool skill_effect = true)
	{
		if (value == 0)
			return 0;
		else if (value < 0)
		{
			if (skill_effect and has_skill(building, 特技_法治))
				value = int(value * pk::core::skill_constant_value(特技_法治) / 100.f);
		}
		return value;
	}

	int add_public_order(pk::city @city, int value, bool effect = false, bool skill_effect = true)
	{
		value = get_order_change(city, value, skill_effect);
		return pk::add_public_order(city, value, effect);
	}

	int add_public_order(pk::building @building, int value, bool effect = false, bool skill_effect = true)
	{
		int building_id = building.get_id();
		value = get_order_change(building, value, skill_effect);
		if (building_id > -1 and building_id < 据点_城市末)
		{
			// value = get_order_change(building, value);
			return pk::add_public_order(pk::building_to_city(building), value, effect);
		}
		if (building_id >= 据点_城市末 and building_id < 据点_末)
		{
			// value = get_order_change(building, value);
			// auto base_t = ch::get_base_p(building_id);
			int p_order = ch::get_base_p(building_id).public_order;
			int change_value = ((p_order + value) >= 100) ? (100 - p_order) : (((p_order + value) <= 0) ? (-p_order) : value);
			// int change_value = ((base_t.public_order + value) >= 100) ? (100 - base_t.public_order) : (((base_t.public_order + value) <= 0) ? (-base_t.public_order) : value);
			ch::get_base_p(building_id).public_order += change_value;
			// base_t.public_order = base_t.public_order + change_value;
			//
			if (effect)
				pk::combat_text(change_value, 6, building.pos); // 1.value,2.effct_id,3.pos
			return change_value;
		}
		return 0;
	}

	int add_tp(pk::force @force, int tp, pk::point pos)
	{
		if (tp > 0)
			return pk::add_tp(force, tp * 2, pos);
		else
			return pk::add_tp(force, tp, pos);
	}

	int add_revenue_bonus(int base_id, int value)
	{
		if (base_id > -1 and base_id < 据点_末)
		{
			auto base_t = ch::get_base_p(base_id);
			uint16 max = base_id < 城市_末 ? 300 : 150;
			if (base_t.revenue_bonus > max)
				return 0;
			if (uint16(base_t.revenue_bonus + value) > max)
				value = max - base_t.revenue_bonus; // 人口下限
			base_t.revenue_bonus += value;
			return value;
		}
		return 0;
	}

	int add_harvest_bonus(int base_id, int value)
	{
		if (base_id > -1 and base_id < 据点_末)
		{
			auto base_t = ch::get_base_p(base_id);
			uint16 max = base_id < 城市_末 ? 2500 : 1250;
			if (base_t.harvest_bonus > max)
				return 0;
			if (uint16(base_t.harvest_bonus + value) > max)
				value = max - base_t.harvest_bonus; // 人口下限
			base_t.harvest_bonus += value;
			return value;
		}
		return 0;
	}

	int add_population(int base_id, int value, bool include_mil_pop = false)
	{
		if (base_id > -1 and base_id < 据点_末)
		{
			auto base_t = ch::get_base_p(base_id);
			int pre_population = base_t.population;
			if ((pre_population + value) < 5000)
				value = 5000 - pre_population; // 人口下限
			// if (base_id == 城市_襄阳) pk::trace(pk::format("add_population,襄阳人口：{}，value:{}", base_t.population, value));

			base_t.population += value;
			if (include_mil_pop)
				base_t.mil_pop_all += uint32(value * 0.3f);
			// 城市的升级变成主动操作
			// if (value > 0 and base_id < 城市_末) // 当人口增长超过阈值时城市升级
			//{
			//	bool upgrade = false;
			//	int level = 0;
			//	if (pre_population < 一级城市阈值 and (pre_population + value) >= 一级城市阈值)
			//	{
			//		upgrade = true;
			//		level = 1;
			//	}
			//	if (pre_population < 二级城市阈值 and (pre_population + value) >= 二级城市阈值)
			//	{
			//		upgrade = true;
			//		level = 2;
			//	}
			//	if (pre_population < 三级城市阈值 and (pre_population + value) >= 三级城市阈值)
			//	{
			//		upgrade = true;
			//		level = 3;
			//	}
			//	if (pre_population < 四级城市阈值 and (pre_population + value) >= 四级城市阈值)
			//	{
			//		upgrade = true;
			//		level = 4;
			//	}
			//	if (upgrade)
			//		set_interior_land(base_id);
			// }
			return value;
		}
		return 0;
	}

	int add_troops(pk::unit @unit, int value, bool effect = false, int type = -1)
	{
		int n = cast<pk::func58_t>(pk::get_func(58))(unit, value, type);
		if (effect)
			pk::combat_text(n, 1, unit.pos);
		return n;
	}

	int add_troops(pk::city @city, int value, bool effect = false, int type = -1)
	{
		int n = 0;
		if (type == 104 and value > 0) // 104暂定为征兵模式，伴随兵役人口变化
		{
			auto base_t = ch::get_base_p(city.get_id());
			if (base_t.mil_pop_all >= 0)
			{
				value = pk::min(base_t.mil_pop_all, value); // 如果值小于预备兵，改写value
			}
			n = cast<pk::func59_t>(pk::get_func(59))(city, value, type);
			add_mil_pop_all(city.get_id(), -n);
		}
		else if (type == 105 and value > 0) // 105暂定为募兵模式，伴随总兵役人口变化
		{
			auto base_t = ch::get_base_p(city.get_id());
			if (base_t.population >= 0 and base_t.mil_pop_all >= 0)
			{
				value = pk::min(pk::min(base_t.mil_pop_all, base_t.population), int(0.5f * value)) * 2; // 如果值小于总兵役人口，改写value
			}
			n = cast<pk::func59_t>(pk::get_func(59))(city, value, type);
			add_mil_pop_all(city.get_id(), -int(0.5f * n)); // base_t.mil_pop_all -= int(0.5f * n);
			add_population(city.get_id(), -int(0.5f * n));	// base_t.population -= int(0.5f * n);
		}
		else
		{
			n = cast<pk::func59_t>(pk::get_func(59))(city, value, type);
		}

		if (effect)
			pk::combat_text(n, 1, city.pos);
		return n;
	}

	int add_troops(pk::building @building, int value, bool effect = false, int type = -1)
	{
		int n = 0;
		int building_id = building.get_id();
		if (type == 104 and value > 0) // 104暂定为征兵模式，伴随兵役人口变化
		{
			auto base_t = ch::get_base_p(building_id);
			if (base_t.mil_pop_all >= 0)
			{
				value = pk::min(base_t.mil_pop_all, value); // 如果值小于预备兵，改写value
			}
			n = cast<pk::func60_t>(pk::get_func(60))(building, value, type);
			add_mil_pop_all(building_id, -n); // base_t.mil_pop_av -= n;
		}
		else if (type == 105 and value > 0) // 104暂定为征兵模式，伴随总兵役人口变化
		{
			auto base_t = ch::get_base_p(building_id);
			if (base_t.mil_pop_all >= 0)
			{
				value = pk::min(base_t.mil_pop_all, value); // 如果值小于总兵役人口，改写value
			}
			n = cast<pk::func60_t>(pk::get_func(60))(building, value, type);
			add_mil_pop_all(building_id, -n);
		}
		else
		{
			n = cast<pk::func60_t>(pk::get_func(60))(building, value, type);
		}

		if (effect and n != 0)
			pk::combat_text(n, 1, building.pos);
		return n;
	}

	int add_mil_pop_all(int base_id, int value) // 设定总兵役上限不超过人口的1/3
	{
		auto base_t = ch::get_base_p(base_id);
		if (value >= 0)
		{
			if (base_t.population <= uint32((base_t.mil_pop_all + value) * 3))
				value = int(base_t.population / 3 - base_t.mil_pop_all);
		}
		else
		{
			if ((base_t.mil_pop_all + value) < 0)
				value = -base_t.mil_pop_all;
		}
		base_t.mil_pop_all += value;
		return value;
	}

	int add_mil_pop_av(int base_id, int value) // 设定现兵役上限不超过人口的1/4
	{
		auto base_t = ch::get_base_p(base_id);
		int pre_value = value;
		if (value >= 0)
		{
			if (base_t.population <= uint32((base_t.mil_pop_av + value) * 4))
				value = int(base_t.population / 4 - base_t.mil_pop_av);
		}
		else
		{
			if ((base_t.mil_pop_av + value) < 0)
				value = -base_t.mil_pop_av;
		}
		base_t.mil_pop_av += value;
		return value;
	}
	/* 设置部队状态
	@param type      0 计略晕, 1 物理晕, 2 自然晕*/
	bool set_status(pk::unit @unit, pk::unit @by, int status, int time, int type, bool sound = true)
	{
		if (status == 部队状态_混乱 && type > 0 && has_skill(unit, 特技_治军)) // 治军免物理晕
		{
			trace("zhi jun");
			return false;
		}
		pk::set_status(unit, by, status, time, sound);
		return true;
	}

	int get_max_energy(bool has_tech = true)
	{
		int max_energy = 0;
#if param_set
		max_energy = has_tech ? pk::get_stat_param().tech_max_energy: pk::get_stat_param().max_energy;
#endif
#if not_param_set
		max_energy = has_tech ? int(pk::core["部队.熟练兵最大气力"]) : int(pk::core["部队.最大气力"]);
#endif		
		return max_energy;
	}

	int get_force_gold(pk::force @force)
	{
		// 分别获取城，港关，部队的金
		int n = 0;
		pk::list<pk::building @> building_list = pk::get_building_list();
		for (int i = 0; i < building_list.count; i++)
		{
			pk::building @building0 = building_list[i];
			int force0_id = building0.get_force_id();
			if (!pk::is_alive(building0) or force0_id != force.get_id())
				continue;
			n += pk::get_gold(building0);
		}
		pk::list<pk::unit @> unit_list = pk::get_unit_list(force);
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;
			n += unit0.gold;
		}
		return n;
	}

	int get_force_food(pk::force @force)
	{
		// 分别获取城，港关，部队的粮
		int n = 0;
		pk::list<pk::building @> building_list = pk::get_building_list();
		for (int i = 0; i < building_list.count; i++)
		{
			pk::building @building0 = building_list[i];
			int force0_id = building0.get_force_id();
			if (!pk::is_alive(building0) or force0_id != force.get_id())
				continue;
			n += pk::get_food(building0);
		}
		pk::list<pk::unit @> unit_list = pk::get_unit_list(force);
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;
			n += unit0.food;
		}
		return n;
	}

	// 只计算枪戟弩马
	int get_force_weapon(pk::force @force)
	{
		// 分别获取城，港关，部队的粮
		int n = 0;
		pk::list<pk::building @> building_list = pk::get_building_list();
		for (int i = 0; i < building_list.count; i++)
		{
			pk::building @building0 = building_list[i];
			int force0_id = building0.get_force_id();
			if (!pk::is_alive(building0) or force0_id != force.get_id())
				continue;
			n += pk::get_weapon_amount(building0, 1);
			n += pk::get_weapon_amount(building0, 2);
			n += pk::get_weapon_amount(building0, 3);
			n += pk::get_weapon_amount(building0, 4);
		}

		pk::list<pk::unit @> unit_list = pk::get_unit_list(force);
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;
			if (unit0.weapon == 兵器_枪 or unit0.weapon == 兵器_戟 or unit0.weapon == 兵器_弩 or unit0.weapon == 兵器_战马)
				n += unit0.troops;
		}
		return n;
	}

	// 只计算任意
	int get_force_weapon(pk::force @force, int weapon_id)
	{
		// 分别获取城，港关，部队的兵装
		int n = 0;
		pk::list<pk::building @> building_list = pk::get_building_list();
		for (int i = 0; i < building_list.count; i++)
		{
			pk::building @building0 = building_list[i];
			int force0_id = building0.get_force_id();
			if (!pk::is_alive(building0) or force0_id != force.get_id())
				continue;
			n += pk::get_weapon_amount(building0, weapon_id);
		}

		pk::list<pk::unit @> unit_list = pk::get_unit_list(force);
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;
			if (unit0.weapon == weapon_id)
				n += unit0.troops;
		}
		return n;
	}

	int get_force_person_count(pk::force @force)
	{
		// 分别获取城，港关，部队的粮
		int n = 0;
		pk::list<pk::person @> person_list = pk::get_person_list(force, pk::mibun_flags(身份_一般, 身份_君主, 身份_太守, 身份_都督));
		n = person_list.count;
		return n;
	}

	/*仇视系统的尝试，因为受伤致死的存在，没办法进行了
	vold kill(person@ self, person@ by = null, hex_object@ where = null, person@ successor = null, int type = 0)
	{
		if (by !is null)
		{
			//区分父，母，配偶，义兄弟，子嗣，亲爱

			pk::add_dislike();
		}
		pk::kill(self, by, where, successor, type);
	}

	bool isFriend(pk::person@ person1, pk::person@ person2)
	{
		bool result = false;

		if (pk::is_gikyoudai(person1, person2.get_id()))
			result = true;
		if (pk::is_fuufu(person1, person2.get_id()))
			result = true;
		if (pk::is_ketsuen(person1, person2.get_id()))
			result = true;
		if (pk::is_oyako(person1, person2.get_id()))
			result = true;
		return result;
	}*/

	int base_num_person_count_district(pk::building @building)
	{

		pk::district @district = pk::get_district(building.get_district_id());
		int total_person_count = pk::get_person_list(district, pk::mibun_flags(身份_君主, 身份_都督, 身份_太守, 身份_一般)).count;
		int total_base_count = ch::get_base_list(district).count;
		int total_city_count = pk::get_city_list(district).count;

		// 大城市2倍权重.计算两次
		// 考虑到别的城市可能处于战争状态或者前线之类的,基准数字下调一些.(1人左右),在小城自己判断的时候再加上
		// 这个人数制约了小城非战斗状态下的,正常调度获得的人数上限.
		// 假如势力有10个人,1大城1小城,这时候基准需求则为2人.大城8人
		int num = total_person_count / (total_base_count + total_city_count) - 1;
		return num;
	}

	int base_num_person_count_force(pk::building @building)
	{
		pk::force @force = pk::get_force(building.get_force_id());
		int total_person_count = pk::get_person_list(force, pk::mibun_flags(身份_君主, 身份_都督, 身份_太守, 身份_一般)).count;
		int total_base_count = ch::get_base_list(force).count;
		int total_city_count = pk::get_city_list(force).count;

		// 大城市2倍权重.计算两次
		// 考虑到别的城市可能处于战争状态或者前线之类的,基准数字下调一些.(1人左右),在小城自己判断的时候再加上
		// 这个人数制约了小城非战斗状态下的,正常调度获得的人数上限.
		// 假如势力有10个人,1大城1小城,这时候基准需求则为2人.大城8人
		int num = total_person_count / (total_base_count + total_city_count);
		return num;
	}

	int get_max_effective_troops(pk::building @building)
	{
		// 战力是兵力兵装和人数合计的结果.
		int num = 0;
		int effective_person_count = pk::get_idle_person_list(building).count;
		int effective_weapon = pk::get_weapon_amount(building, 1) + pk::get_weapon_amount(building, 2) + pk::get_weapon_amount(building, 3) + pk::get_weapon_amount(building, 4);
		num = pk::min(building.troops, int(effective_weapon * 0.85), (effective_person_count - 2) * 6000); // 不一定每个人都能战斗,简化计算减去2个.
		num = pk::max(num, building.troops / 3);
		num = num * building.energy / 150;
		return num;
	}

	pk::list<pk::building @> get_base_list(pk::district @district)
	{
		pk::list<pk::building @> list;
		for (int i = 0; i < 据点_末; i++)
		{
			pk::building @building = pk::get_building(i);
			if (building.get_district_id() == district.get_id())
				list.add(building);
		}
		return list;
	}

	pk::list<pk::building @> get_base_list(pk::force @force)
	{
		pk::list<pk::building @> list;
		if (force is null) return list;

		for (int i = 0; i < 据点_末; i++)
		{
			pk::building @src = pk::get_building(i);
			if (src.get_force_id() == force.get_id())
				list.add(src);
		}
		return list;
	}

	pk::list<pk::building @> get_base_list()
	{
		pk::list<pk::building @> list;
		for (int i = 0; i < 据点_末; i++)
		{
			pk::building @src = pk::get_building(i);
			list.add(src);
		}
		return list;
	}

	pk::list<pk::building @> get_base_list(int province_id)
	{
		pk::list<pk::building @> list;
		for (int i = 0; i < 据点_末; i++)
		{
			pk::building @src = pk::get_building(i);
			if (pk::get_province_id(src.get_pos()) == province_id)
				list.add(src);
		}
		return list;
	}

	int get_weapon_cost(int weapon_id)
	{
		return pk::get_equipment(weapon_id).gold_cost;
	}

	string get_weapon_name2(int weapon_id)
	{
		string weapon_name;
		switch (weapon_id)
		{
			case 兵器_剑:
				weapon_name = "剑";
				break;
			case 兵器_枪:
				weapon_name = "枪";
				break;
			case 兵器_戟:
				weapon_name = "戟";
				break;
			case 兵器_弩:
				weapon_name = "弩";
				break;
			case 兵器_战马:
				weapon_name = "战马";
				break;
			case 兵器_冲车:
				weapon_name = "冲车";
				break;
			case 兵器_井阑:
				weapon_name = "井阑";
				break;
			case 兵器_投石:
				weapon_name = "投石";
				break;
			case 兵器_木兽:
				weapon_name = "木兽";
				break;
			case 兵器_走舸:
				weapon_name = "走舸";
				break;
			case 兵器_楼船:
				weapon_name = "楼船";
				break;
			case 兵器_斗舰:
				weapon_name = "斗舰";
				break;
			default:
				weapon_name = "??";
				break;
		}
		return weapon_name;
	}

	pk::int_int base_range_self_and_enemy_troops(pk::building @building, int distance)
	{
		int enemy_troops = 0;
		int self_troops = 0;
		pk::list<pk::unit @> unit_list = pk::get_unit_list();
		pk::point building_pos = building.get_pos();
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;
			if (pk::is_enemy(unit0, building) and pk::get_distance(building_pos, unit0.get_pos()) < distance + (building.facility == 设施_都市 ? 1 : 0))
			{
				int id = pk::get_building_id(unit0.pos);
				if (id == building.get_id())
					enemy_troops += unit0.troops;
			}
			else
			{
				if (pk::get_distance(building_pos, unit0.get_pos()) < distance + (building.facility == 设施_都市 ? 1 : 0))
					self_troops += unit0.troops;
			}
		}

		return pk::int_int(self_troops, enemy_troops);
	}

	int city_spec_troops(pk::building @building)
	{
		int total = 0;
		if (building.get_id() < 据点_末)
		{
			for (int j = 0; j < 最大城市县城数; ++j)
			{
				int spec_id = ch::get_base_spec(building.get_id(), j);
				if (ch::is_valid_spec_id(spec_id))
				{
					auto spec_t = ch::get_spec_p(spec_id);
					int person_id = spec_t.person;

					if (spec_t.person >= 0 and spec_t.person < 武将_末 and spec_t.troops>2000)
					{
						total += spec_t.troops - 2000;
					}
				}
			}
		}
		return total;
	}
	bool is_gate(int dst_id)
	{
		if (dst_id == 铃据点_壶关 or dst_id == 铃据点_虎牢关 or dst_id == 铃据点_潼关 or dst_id == 铃据点_函谷关 or dst_id == 铃据点_寰辕关 or dst_id == 铃据点_阳平关 or dst_id == 铃据点_剑门关 or dst_id == 铃据点_绵竹关)
			return true;
		return false;
	}

	int base_range_enemy_troops_from_player(pk::building @building, int self_distance)
	{
		int enemy_troops = 0;
		pk::list<pk::unit @> unit_list = pk::get_unit_list();
		pk::point building_pos = building.get_pos();
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;
			if (pk::is_enemy(unit0, building) and unit0.is_player())
			{
				int id = pk::get_building_id(unit0.pos);
				if (id == building.get_id())
					enemy_troops += unit0.troops;
			}
		}

		return enemy_troops;
	}


	bool is_valid_routepath(int src, int dst, int force_id)
	{
		if (pk::get_building_distance(src, dst) >= 5) return false;
		//第一层搜索
		for (int i = 0; i < 6; i++)
		{
			int neighbor_1 = pk::get_neighbor_area_building(src, i);
			if (neighbor_1 >= 0 && neighbor_1 <= 据点_末 and neighbor_1 == dst)
			{
				return true;
			}
			//第二层搜索
			else if (pk::get_building(neighbor_1).get_force_id() == force_id)
			{
				for (int j = 0; j < 6; j++)
				{
					int neighbor_2 = pk::get_neighbor_area_building(neighbor_1, j);
					if (neighbor_2 >= 0 && neighbor_2 <= 据点_末 and neighbor_2 == dst)
					{
						return true;
					}
					//第三层搜索
					else if (pk::get_building(neighbor_2).get_force_id() == force_id)
					{
						for (int k = 0; k < 6; k++)
						{
							int neighbor_3 = pk::get_neighbor_area_building(neighbor_2, k);
							if (neighbor_3 >= 0 && neighbor_3 <= 据点_末 and neighbor_3 == dst)
							{
								return true;
							}
												//第四层搜索
							else if (pk::get_building(neighbor_3).get_force_id() == force_id)
							{
								for (int q = 0; q < 6; q++)
								{
									int neighbor_4 = pk::get_neighbor_area_building(neighbor_3, q);
									if (neighbor_4 >= 0 && neighbor_4 <= 据点_末 and neighbor_4 == dst)
									{
										return true;
									}

								}
							}

						}
					}

				}
			}
		}
		return false;

	}


	pk::int_int get_mid_base_id(int src, int dst)
	{
		int temp_id = -1;
		int route_type = -1;
		if (pk::get_building_distance(src, dst) == 1) return pk::int_int(dst, pk::get_neighbor_area_route(src, dst));
		if (pk::get_building_distance(src, dst) > 2) return pk::int_int(-1, -1);

		for (int i = 0; i < 6; i++)
		{
			int neighbor_base_id = pk::get_neighbor_area_building(src, i);
			if (neighbor_base_id >= 0 && neighbor_base_id <= 据点_末)
			{
				if (neighbor_base_id == dst)
					return pk::int_int(dst, pk::get_neighbor_area_route(src, i));
				int base_distance = pk::get_building_distance(neighbor_base_id, dst);
				if (base_distance == 1 and pk::get_building(neighbor_base_id).get_force_id() == pk::get_building(src).get_force_id())
				{
					temp_id = neighbor_base_id;
					route_type = pk::get_neighbor_area_route(src, i);
				}
			}
		}
		return pk::int_int(temp_id, route_type);
	}


	pk::int_int get_building_around_selfattack_enemy_power(pk::building @dst, pk::force @force)
	{
		int def_enemy_power = 0;
		int atk_self_power = 0;
		pk::array<pk::unit @> arr_unit = pk::list_to_array(pk::get_unit_list());
		for (int i = 0; i < int(arr_unit.length); i++)
		{
			pk::unit @unit = arr_unit[i];
			int unit_id = unit.get_id();

			if (unit_id == -1)
				continue;
			// 考虑城市范围内和周围5格所有敌军(以防止城市在边缘)
			if (pk::get_building_id(unit.pos) != dst.get_id() and pk::get_distance(unit.pos, dst.pos) > 5)
				continue;

			if (unit.get_force_id() == dst.get_force_id()) // 部队和据点属于同一势力
			{
				def_enemy_power += unit.troops * (unit.attr.stat[部队能力_攻击] + unit.attr.stat[部队能力_防御]) / 100; // 区域内防御军总兵力                                                                             // 区域内防御军部队数量
			}
			else if ((unit.get_force_id() == force.get_id() or force.ally[unit.get_force_id()]) and pk::is_enemy(unit, dst))
			{
				atk_self_power += unit.troops * (unit.attr.stat[部队能力_攻击] + unit.attr.stat[部队能力_防御]) / 100; // 区域内己方或者同盟军进攻总兵力
			}
		}

		return pk::int_int(atk_self_power, def_enemy_power);
	}

	int attatking_base_total_power_from_force(pk::building @dst, pk::force @force)
	{
		int atk_self_power = 0;
		pk::list<pk::unit @> unit_list = pk::get_unit_list(force);

		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit = unit_list[i];
			if (!pk::is_alive(unit))
				continue;

			if (pk::get_distance(unit.pos, dst.pos) >= 30)
				continue;

			if (!pk::is_enemy(unit, dst))
				continue;

			//  跳过非普通类型部队
			if (unit.type == 部队类型_运输)
				continue;


			if ((unit.order != 部队任务_征服 and unit.order != 部队任务_攻城 and unit.target_type != 部队任务对象_据点))
				continue;

			if (!pk::is_valid_base_id(unit.target) or unit.target >= 据点_末)
				continue;

			atk_self_power += unit.troops * (unit.attr.stat[部队能力_攻击] + unit.attr.stat[部队能力_防御]) / 100; // 区域内己方或者同盟军进攻总兵力
		}

		return atk_self_power;
	}

	int attatking_base_field_power_from_force(pk::building @dst, pk::force @force)
	{
		int atk_self_power = 0;
		pk::list<pk::unit @> unit_list = pk::get_unit_list(force);

		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit = unit_list[i];
			if (!pk::is_alive(unit))
				continue;

			if (pk::get_distance(unit.pos, dst.pos) >= 30)
				continue;

			if (!pk::is_enemy(unit, dst))
				continue;

			//  跳过非普通类型部队
			if (unit.type == 部队类型_运输)
				continue;

			//只考虑野战部队
			if (unit.weapon > 兵器_战马)
				continue;


			if ((unit.order != 部队任务_征服 and unit.order != 部队任务_攻城 and unit.target_type != 部队任务对象_据点))
				continue;

			if (!pk::is_valid_base_id(unit.target) or unit.target >= 据点_末)
				continue;

			atk_self_power += unit.troops * (unit.attr.stat[部队能力_攻击] + unit.attr.stat[部队能力_防御]) / 100; // 区域内己方或者同盟军进攻总兵力
		}

		return atk_self_power;
	}

	int enemy_troop_base_range(pk::building @building)
	{
		int enemy_troops = 0;
		pk::list<pk::unit @> unit_list = pk::get_unit_list();
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;
			if (!pk::is_enemy(unit0, building))
				continue;

			int id = pk::get_building_id(unit0.pos);
			if (id == building.get_id())

				enemy_troops += unit0.troops;
		}
		return enemy_troops;
	}


	int base_enemy_not_from_force(pk::building @building, pk::force @force)
	{
		int enemy_power = 0;
		if (!pk::is_valid_force_id(force.get_id())) return 0;
		pk::list<pk::unit @> unit_list = pk::get_unit_list();
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;

			if (pk::is_enemy(unit0, force))
				continue;

			int id = pk::get_building_id(unit0.pos);
			if (id != building.get_id())
			continue;

			if(pk::get_distance(building.pos,unit0.pos) >10)
			continue;
			

				enemy_power += unit0.troops * (unit0.attr.stat[部队能力_攻击] + unit0.attr.stat[部队能力_防御]) / 2 / 10000;
		}
		return enemy_power;
	}

	int enemy_troop_base_near_distance(pk::building @building, int distance)
	{
		int enemy_troops = 0;
		pk::list<pk::unit @> unit_list = pk::get_unit_list();
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;
			if (!pk::is_enemy(unit0, building))
				continue;

			if (pk::get_distance(building.get_pos(), unit0.get_pos()) < distance + (building.facility == 设施_都市 ? 1 : 0))
				enemy_troops += unit0.troops;
		}
		return enemy_troops;
	}

	int self_troop_base_near_distance(pk::building @building, int distance)
	{
		int self_troops = 0;
		pk::list<pk::unit @> unit_list = pk::get_unit_list();
		for (int i = 0; i < unit_list.count; i++)
		{
			pk::unit @unit0 = unit_list[i];
			if (!pk::is_alive(unit0))
				continue;
			if (pk::is_enemy(unit0, building))
				continue;

			if (pk::get_distance(building.get_pos(), unit0.get_pos()) < distance + (building.facility == 设施_都市 ? 1 : 0))
				self_troops += unit0.troops;
		}
		return self_troops;
	}

	// same_force - 同势力。true-只统计非同势力据点 | false-只统计敌对势力，即剔除同盟跟停战
	int neibor_enemy_city_count(pk::building @building, int distance, bool same_force = true)
	{
		int enemy_city_count = 0;
		for (int i = 0; i < 城市_末; i++)
		{
			pk::building @neighbor_building = pk::get_building(i);
			if (!same_force and !pk::is_enemy(building, neighbor_building)) continue;
			if (same_force and building.get_force_id() == neighbor_building.get_force_id()) continue;

			int distanceToBuilding = pk::get_building_distance(building.get_id(), i, building.get_force_id());
			if (distanceToBuilding > distance)
				continue;
			enemy_city_count++;
		}
		return enemy_city_count;
	}

	// same_force - 同势力。true-只统计非同势力据点 | false-只统计敌对势力，即剔除同盟跟停战
	int neibor_enemy_base_count(pk::building @building, int distance, bool same_force = true)
	{
		int enemy_building_count = 0;
		for (int i = 0; i < 据点_末; i++)
		{
			pk::building @neighbor_building = pk::get_building(i);
			if (!same_force and !pk::is_enemy(building, neighbor_building)) continue;
			if (same_force and building.get_force_id() == neighbor_building.get_force_id()) continue;

			int distanceToBuilding = pk::get_building_distance(building.get_id(), i, building.get_force_id());
			if (distanceToBuilding > distance)
				continue;
			enemy_building_count++;
		}
		return enemy_building_count;
	}

	pk::int_int near_enemy_base_count(pk::building @building)
	{
		int enemy_building_count1 = 0;
		int enemy_building_count2 = 0;
		for (int i = 0; i < 据点_末; i++)
		{
			pk::building @neighbor_building = pk::get_building(i);
			int base_id = building.get_id();

			if (building.get_force_id() == neighbor_building.get_force_id()) continue;
			if (neighbor_building.get_force_id() == -1)  continue;  //空城不算敌人

			int building_distance = pk::get_building_distance(building.get_id(), i, building.get_force_id());
			int unitdistance = unit_distance[i][base_id];
			if (building_distance == 1) enemy_building_count1++;
			else if (building_distance > 1 and unitdistance <= 12) enemy_building_count2++;
		}
		return pk::int_int(enemy_building_count1, enemy_building_count2);
	}

	pk::int_int near_enemy_city_count(pk::building @building)
	{
		int enemy_building_count1 = 0;
		int enemy_building_count2 = 0;
		for (int i = 0; i < 城市_末; i++)
		{
			pk::building @neighbor_building = pk::get_building(i);
			int city_id = pk::get_city_id(building.pos);

			if (building.get_force_id() == neighbor_building.get_force_id()) continue;

			int city_distance = pk::get_city_distance(city_id, i);

			if (city_distance == 1) enemy_building_count1++;
			else if (city_distance == 2) enemy_building_count2++;
		}
		return pk::int_int(enemy_building_count1, enemy_building_count2);
	}

	int when_suppor_calc_reserve_person_count(int building_id, pk::list<pk::person @> idle_person_list, pk::list<pk::person @> person_list)
	{
		// auto idle_person_list = pk::get_idle_person_list(pk::get_building(building_id));
		// auto person_list = pk::get_person_list(pk::get_building(building_id), pk::mibun_flags(身份_君主, 身份_都督, 身份_太守, 身份_一般));
		int min_count = ((building_id < 城市_末) ? 2 : 1);

		// 战斗据点
		if (ch::enemy_troop_base_range(pk::get_building(building_id)) > 0)
		{
			if (building_id < 城市_末)
				min_count += 5;
			else
				min_count += 2;
		}

		// 危险据点
		else if (ch::neibor_enemy_base_count(pk::get_building(building_id), 1) >= 3)
		{
			if (building_id < 城市_末)
				min_count += 3;
			else
				min_count += 2;
		}

		// 前线据点
		else if (ch::neibor_enemy_base_count(pk::get_building(building_id), 1) >= 1)
		{
			if (building_id < 城市_末)
				min_count += 1;
			else
				min_count += 1;
		}
		return min_count;
	}

	int normal_calc_reserve_person_count(int building_id)
	{
		auto idle_person_list = pk::get_idle_person_list(pk::get_building(building_id));
		auto person_list = pk::get_person_list(pk::get_building(building_id), pk::mibun_flags(身份_君主, 身份_都督, 身份_太守, 身份_一般));
		int min_count = ((building_id < 城市_末) ? 5 : 3);

		// 战斗据点
		if (ch::enemy_troop_base_range(pk::get_building(building_id)) > 0)
		{
			if (building_id < 城市_末)
				min_count += 5;
			else
				min_count += 3;
		}

		// 危险据点
		else if (ch::neibor_enemy_base_count(pk::get_building(building_id), 1) >= 3)
		{
			if (building_id < 城市_末)
				min_count += 3;
			else
				min_count += 2;
		}

		// 前线据点
		else if (ch::neibor_enemy_base_count(pk::get_building(building_id), 1) >= 1)
		{
			if (building_id < 城市_末)
				min_count += 1;
			else
				min_count += 0;
		}
		return min_count;
	}

	string get_call(pk::person @src, pk::person @dst)
	{
		pk::msg_param msg_param(46, src, dst);
		return pk::get_msg(msg_param);
	}
	// 计谋执行部队和目标部队的台词输出:调用msg文件的台词(计谋相关内容- S11MSG01.s11文件)   계략 실행부대 및 대상부대의 대사 출력 : msg 폴더의 s11 파일 대사 소환 (계략관련 내용 - S11MSG01.s11 파일)
	void say_message(int msg_id, pk::person @p0, pk::person @p1, pk::unit @u0, pk::unit @p0_u)
	{
		pk::msg_param msg_param(msg_id, p0, p1);
		@msg_param.unit[0] = @u0;
		pk::say(pk::get_msg(msg_param), p0, p0_u);
	}

	void say_message(int msg_id, pk::person @p0, pk::person @p1, pk::building @b0, pk::building @p0_b)
	{
		pk::msg_param msg_param(msg_id, p0, p1);
		@msg_param.building[0] = @b0;
		pk::say(pk::get_msg(msg_param), p0, p0_b);
	}

	void say_message(int msg_id, int num, pk::person @p0, pk::person @p1, pk::building @b0, pk::building @p0_b)
	{
		pk::msg_param msg_param(msg_id, p0, p1);
		@msg_param.building[0] = @b0;
		msg_param.num[0] = num;
		pk::say(pk::get_msg(msg_param), p0, p0_b);
	}

	void history_log(int msg_id, int num, pk::person @p0, pk::person @p1, pk::building @b0, pk::building @p0_b)
	{
		pk::msg_param msg_param(msg_id, p0, p1);
		@msg_param.building[0] = @b0;
		msg_param.num[0] = num;
		pk::force @force = pk::get_force(p0.get_force_id());
		pk::history_log(p0.get_pos(), force.color, pk::get_msg(msg_param));
	}

	bool player_check(pk::person @person)
	{
		if (pk::is_alive(person))
		{
			pk::force @force = pk::get_force(person.get_force_id());
			if (pk::is_alive(force))
			{
				if (force.is_player())
				{
					pk::district @district = pk::get_district(person.get_district_id());
					if (pk::is_alive(district))
					{
						if (pk::is_player_controlled(district))
							return true;
					}
				}
			}
		}
		return false;
	}

	int get_neighbor_player_base(pk::building @building)
	{
		if (building.get_id() >= 据点_末)
			return 0;
		int count = 0;
		for (int base_id = 0; base_id < 据点_末; base_id++)
		{
			pk::building @building0 = pk::get_building(base_id);
			if(pk::get_building_distance(building.get_id(),base_id) !=1) continue;
			if (building0.is_player() and base_id < 城市_末)
				count += 1;
			else if (building0.is_player() and base_id >= 城市_末)
				count += 1;
		}
		return count;
	}


	int get_attacking_near_enemy_base(pk::ai_context @context, pk::building @building)
	{
		int building_id = building.get_id();

		if (pk::is_valid_base_id(building_id))
		{
			if (pk::is_valid_city_id(building_id))
			{
				pk::city @city = pk::get_city(building_id);
				// 确认邻近城市为目标城市，满足条件执行破坏指令
				for (int i = 0; i < context.target_count; ++i)
				{
					if (context.type[i] == 1) // 类型1为攻击
					{
						int target = context.target[i];
						if (pk::is_neighbor_city(city, target))
							return target;
					}
				}
			}
			else
			{
				// 确认邻近城市为目标城市，满足条件执行破坏指令
				for (int i = 0; i < context.target_count; ++i)
				{
					if (context.type[i] == 1) // 类型1为攻击
					{
						int target = context.target[i];
						if (pk::is_neighbor_base(building_id, target))
							return target;
					}
				}
			}
		}
		return -1;
	}

	pk::list<pk::person @> get_member_list(pk::unit @unit)
	{
		pk::list<pk::person @> list;
		for (int i = 0; i < 3; ++i)
		{
			if (pk::is_valid_person_id(unit.member[i]))
			{
				pk::person @person0 = pk::get_person(unit.member[i]);
				if (pk::is_alive(person0))
					list.add(person0);
			}
		}
		return list;
	}

	int get_city_spec(int city_id, int index)
	{
		return city_spec[city_id][index];
	}

	int get_base_spec(int base_id, int index)
	{
		return base_spec[base_id][index];
	}

	void 特殊地名争夺处理(int facility_id, int force_id, pk::point pos, int pre_building_id)
	{
		if (特定地点特定设施可争夺)
		{
			int spec_id = to_spec_id(pre_building_id);
			if (is_valid_spec_id(spec_id))
			{
				if (force_id != -1)
				{
					pk::force @force0 = pk::get_force(force_id);
					if (facility_id == 设施_连弩橹 or facility_id == 设施_箭楼)
						facility_id = pk::has_tech(force0, 技巧_施设强化) ? 设施_连弩橹 : 设施_箭楼;
					else if (facility_id == 设施_阵 or facility_id == 设施_砦 or facility_id == 设施_城塞)
						facility_id = pk::has_tech(force0, 技巧_设施强化) ? (pk::has_tech(force0, 技巧_城壁强化) ? 设施_城塞 : 设施_砦) : 设施_阵;
					// pk::trace(pk::format("最终生成设施类型，id为：{}", facility_id));
				}
				pk::building @building0 = pk::create_spec(pk::get_facility(ch::get_spec_facility_id(spec_id)), pos, force_id, spec_id);
				pk::complete(building0);
				building0.hp = 1500;
				reset_spec(spec_id, building0.get_id());
			}
		}
	}

	void 特殊地名争夺处理(pk::building @target_building, pk::unit @attacker, int& out destroyed_facility_id, int& out destroy_unit_id, int& out hp_damage, pk::point& out destroyed_building_pos, bool& out destroy_flag)
	{
		if (特定地点特定设施可争夺)
		{
			if (hp_damage >= int(target_building.hp))
			{
				if (地名设施.find(target_building.facility) >= 0)
				{
					// pk::trace(pk::format("全局pos2,facility{}", target_building.facility));
					for (int i = 0; i < get_spec_end(); i++) // 注意，地名末和length不一定一致
					{
						pk::point pos0 = get_spec_pos(i);
						if (pos0 == target_building.pos)
						{
							// pk::trace(pk::format("破坏时 x:{},y:{}.", target_building.pos.x, target_building.pos.y));
							if (attacker.get_force_id() < 非贼势力_末)
							{
								destroyed_facility_id = target_building.facility;
								destroyed_building_pos = target_building.pos;
								destroy_unit_id = attacker.get_id();
								destroy_flag = true;
								break;
							}
							else
							{
								hp_damage = 0;
								pk::create_effect(91, target_building.pos);
								pk::set_district(target_building, pk::get_district(attacker.get_district_id()), 0);
								// target_building.hp = pk::get_max_hp(target_building);
								reset_spec(i);
								break;
							}
						}
					}
				}
			}
			else
				hp_damage = hp_damage;
		}
	}

	void 特殊地名设施_重建(pk::unit @unit, int& destroy_unit_id, int& destroyed_facility_id, pk::point& destroyed_building_pos, bool& destroy_flag)
	{
		if (destroy_unit_id != -1 and destroyed_building_pos.x != -1 and destroyed_facility_id != -1 and destroy_flag)
		{
			if (destroy_unit_id == unit.get_id() and 地名设施.find(destroyed_facility_id) >= 0)
			{
				pk::hex @hex0 = pk::get_hex(destroyed_building_pos);
				if (hex0.has_unit)
				{
					pk::kill(pk::get_unit(destroyed_building_pos));
				}
				if (hex0.has_building)
				{
					pk::kill(pk::get_building(destroyed_building_pos));
				}
				// pk::trace(pk::format("攻击部队id:{}.被摧毁建筑id：{}",destroy_unit.get_id(), destroyed_building.get_id()));
				// pk::trace(pk::format("建筑id:{}.建筑位置：{},{},攻击部队势力：{}",destroyed_building.facility, destroyed_building.pos.x, destroyed_building.pos.y, destroy_unit.get_force_id()));
				// auto pos = destroyed_building.pos;
				// pos.x = pos.x + 1
				pk::unit @destroy_unit = pk::get_unit(destroy_unit_id);
				pk::facility @destroy_facility = pk::get_facility(destroyed_facility_id);
				int destroy_force = -1;
				if (destroy_unit.get_force_id() < 非贼势力_末)
					destroy_force = destroy_unit.get_force_id();
				pk::create_effect(91, destroyed_building_pos);
				// pk::trace(pk::format("攻击部队id:{}. 重建势力id:{}",destroy_unit.get_id(),destroy_force));
				// pk::trace(pk::format("x:{},y:{}.",destroyed_building_pos.x,destroyed_building_pos.y));
				// pk::trace(pk::format("设施类型：{}",destroy_facility.get_id()));
				// pk::trace(pk::format("重建势力id:{}",destroy_force));
				pk::building @building0 = pk::create_building(destroy_facility, destroyed_building_pos, destroy_force);
				pk::complete(building0);
				// 初始化
				destroy_unit_id = -1;
				destroyed_facility_id = -1;
				destroyed_building_pos.x = -1;
				destroyed_building_pos.y = -1;
				destroy_flag = false;
			}
		}
	}

	void 特殊地名设施_重建(pk::unit @unit, int& destroy_unit_id, int& destroyed_facility_id, pk::point& destroyed_building_pos, bool& destroy_flag, int call_id)
	{
		if (destroy_unit_id != -1 and destroyed_building_pos.x != -1)
		{
			if (destroy_unit_id == unit.get_id() and destroy_flag)
			{
				if (地名设施.find(destroyed_facility_id) >= 0)
				{
					pk::hex @hex0 = pk::get_hex(destroyed_building_pos);
					if (hex0.has_unit)
					{
						pk::kill(pk::get_unit(destroyed_building_pos));
					}
					if (hex0.has_building)
					{
						pk::kill(pk::get_building(destroyed_building_pos));
					}
					// pk::trace(pk::format("攻击部队id:{}.被摧毁建筑id：{}",destroy_unit.get_id(), destroyed_building.get_id()));
					// pk::trace(pk::format("建筑id:{}.建筑位置：{},{},攻击部队势力：{}",destroyed_building.facility, destroyed_building.pos.x, destroyed_building.pos.y, destroy_unit.get_force_id()));
					// auto pos = destroyed_building.pos;
					// pos.x = pos.x + 1
					pk::unit @destroy_unit = pk::get_unit(destroy_unit_id);
					pk::facility @destroy_facility = pk::get_facility(destroyed_facility_id);
					int destroy_force = -1;
					if (destroy_unit.get_force_id() < 非贼势力_末)
						destroy_force = destroy_unit.get_force_id();
					pk::create_effect(91, destroyed_building_pos);
					// pk::trace(pk::format("攻击部队id:{}. 重建势力id:{}",destroy_unit.get_id(),destroy_force));
					// pk::trace(pk::format("call_id:{}",call_id));
					// pk::trace(pk::format("x:{},y:{}.",destroyed_building_pos.x,destroyed_building_pos.y));
					// pk::trace(pk::format("设施类型：{}",destroy_facility.get_id()));
					// pk::trace(pk::format("重建势力id:{}",destroy_force));

					pk::building @building0 = pk::create_building(destroy_facility, destroyed_building_pos, destroy_force);
					pk::complete(building0);
					// 初始化
					destroy_unit_id = -1;
					destroyed_facility_id = -1;
					destroyed_building_pos.x = -1;
					destroyed_building_pos.y = -1;
					destroy_flag = false;
				}
			}
		}
	}

	pk::person @create_temp_person(int template_id, int person_type)
	{
		if (!pk::is_valid_person_id(template_id)) return null;
		pk::person @t_person = pk::create_bandit(pk::get_person(template_id));//生成的将是和模板武将数值一样的武将
		if (t_person is null) return null;//没有成功生成就直接返回
		pk::set_mibun(t_person,身份_一般);
		auto person_t = ch::get_person_p(t_person.get_id());
		person_t.person_type = person_type;
		return t_person;
	}

	void set_spec_temp_person(pk::person@ f_person, pk::person@ leader, int district_id = -1)
	{
		if (f_person is null) return;
		if (pk::is_valid_district_id(district_id)) pk::set_district(f_person, district_id);

		if (leader.get_id() == 799)
		{
			f_person.sei = pk::encode("土著");
			f_person.mei = pk::encode("士兵");
			f_person.face = 924;
		}

		if (leader.get_id() == 798)
		{
			f_person.sei = pk::encode("乌桓");
			f_person.mei = pk::encode("将领");
			f_person.face = 833;
		}

		f_person.name_read = pk::encode("府兵");
		// if (f_person.mibun == 身份_在野) pk::set_mibun(f_person, 身份_一般);

		// 根据府兵强度来调节府兵的属性
		int 府兵难度 = 0;
		府兵难度 = pk::min(3, ch::get_set_p(0).spec_strength); //if (building.is_player())

		int max_stat = 府兵难度 * 10 + 80;
		int min_stat = 府兵难度 * 10 + 60;

		if (leader !is null)
		{
			f_person.base_stat[武将能力_统率] = pk::max(min_stat, pk::min(max_stat, int(leader.base_stat[武将能力_统率] * 0.9 + 府兵难度 * 10)));
			f_person.base_stat[武将能力_武力] = pk::max(min_stat, pk::min(max_stat, int(leader.base_stat[武将能力_武力] * 0.9 + 府兵难度 * 10)));
			f_person.base_stat[武将能力_智力] = pk::max(min_stat, pk::min(max_stat, int(leader.base_stat[武将能力_智力] * 0.9 + 府兵难度 * 10)));
			f_person.base_stat[武将能力_政治] = pk::max(min_stat, pk::min(max_stat, int(leader.base_stat[武将能力_政治] * 0.9 + 府兵难度 * 10)));
			f_person.skill = 特技_突袭;

			for (int heishu_id = 兵种_枪兵; heishu_id < 兵种_末; heishu_id++)
				f_person.tekisei[heishu_id] = pk::max(leader.tekisei[heishu_id] + ch::randint(府兵难度, 1 + 府兵难度), 2);

			f_person.rank = pk::min(81, leader.rank + 8);
		}

		f_person.update();
	}

	bool is_valid_autoarmy_id(int autoarmy_id)
	{
		if (autoarmy_id >= 0 and autoarmy_id < 组队数_末)
			return true;
		return false;
	}

	bool is_valid_setting_id(int set_id)
	{
		if (set_id >= 0 and set_id < 设定_末)
			return true;
		return false;
	}

	bool is_valid_spec_id(int spec_id)
	{
		if (spec_id >= 0 and spec_id < get_spec_end())
			return true;
		return false;
	}

	int to_spec_id(int building_id)
	{
		if (building_id >= 100 and building_id < (100 + ch::get_spec_end()))
			return (building_id - 100);
		return -1;
	}

	int to_building_id(int spec_id)
	{
		if (is_valid_spec_id(spec_id))
			return (spec_id + 100);
		return -1;
	}

	pk::building @get_spec_building(int spec_id)
	{
		int building_id = to_building_id(spec_id);
		return pk::get_building(building_id);
	}

	int get_spec_id(pk::building @building)
	{
		if (building is null)
			return -1;
		int building_id = building.get_id();
		int spec_id = to_spec_id(building_id);
		return spec_id;
	}

	specialinfo @get_spec_info(int spec_id)
	{
		if (is_valid_spec_id(spec_id))
			return @special_ex[spec_id];
		else
			return null;
	}

	specialinfo @get_spec_info(pk::building @building)
	{
		return get_spec_info(get_spec_id(building));
	}

	string get_spec_name(int spec_id)
	{
		if (pk::is_new_map())
		{
			return 特殊地名设施名称2[spec_id];
		}
		return 特殊地名设施名称[spec_id];
	}

	int get_spec_end()
	{
		if (pk::is_new_map())
		{
			return 地名_末2;
		}
		return 地名_末;
	}

	int get_normal_spec_end()
	{
		return 地名_末 - 5;
	}

	pk::point get_spec_pos(int spec_id)
	{
		if (pk::is_new_map())
		{
			return pk::point(特殊地名设施2[spec_id][1], 特殊地名设施2[spec_id][2]);
		}
		return pk::point(特殊地名设施[spec_id][1], 特殊地名设施[spec_id][2]);
	}

	int get_spec_facility_id(int spec_id)
	{
		if (true)
		{
			return 设施_城塞;
		}
		else
		{
			if (pk::is_new_map())
			{
				return 特殊地名设施2[spec_id][0];
			}
			return 特殊地名设施[spec_id][0];
		}
	}

	bool reset_spec(int spec_id, int building_id = -1)
	{
		// 清空信息
		auto spec_t = ch::get_spec_p(spec_id);
		if (pk::is_valid_person_id(spec_t.person))
			ch::get_person_p(spec_t.person).spec_id = -1; // 清空原来武将的对应记录
		spec_t.person = -1;
		spec_t.troops = 0;
		spec_t.gold = 0;
		spec_t.food = 0;
		if (building_id != -1) spec_t.building_id = building_id;
		pk::building @spec_building = pk::get_building(spec_id + 100);
		if (int(spec_building.hp) > pk::get_max_hp(spec_building))
			spec_building.hp = pk::get_max_hp(spec_building);
		return true;
	}

	int get_spec_person_id(int spec_id)
	{
		if (!is_valid_spec_id(spec_id))
			return -1;
		int person_id = get_spec_p(spec_id).person;
		if (pk::is_valid_person_id(person_id))
			return person_id;
		return -1;
	}

	pk::person @get_spec_person(int spec_id)
	{
		return pk::get_person(get_spec_person_id(spec_id));
	}

	//部队是否是农民、突袭者、雇佣兵
	bool is_临时武将(int person_id)
	{
		if (!pk::is_valid_person_id(person_id))
			return false;
		auto person_t = ch::get_person_p(person_id);
		//16-农民兵，17-府兵，18-突袭者，19-雇佣者
		if (person_t.person_type == 16 or person_t.person_type == 17 or person_t.person_type == 18 or person_t.person_type == 19)
			return true;
		return false;
	}

	string get_weapon_name(int weapon_id)
	{
		auto equp = pk::get_equipment(weapon_id);
		if (pk::is_alive(equp))
			return equp.name;
		return "---";
	}

	string get_force_name(pk::force @force, bool decode = false)
	{
		if (pk::is_alive(force))
		{
			if (decode)
				return pk::decode(pk::get_name(force));
			return pk::get_name(force);
		}
		return "---";
	}

	string get_force_name(int force_id, bool decode = false)
	{
		auto force = pk::get_force(force_id);
		return get_force_name(force, decode);
	}

	string get_person_name(pk::person @person, bool decode = false)
	{
		if (pk::is_alive(person))
		{
			if (decode)
				return pk::decode(pk::get_name(person));
			return pk::get_name(person);
		}
		return "---";
	}

	string get_person_name(int person_id, bool decode = false)
	{
		auto person = pk::get_person(person_id);
		return get_person_name(person, decode);
	}

	string get_spec_person_name(int spec_id)
	{
		pk::person @person = get_spec_person(spec_id);
		return get_person_name(person, false);
	}

	int get_spec_force_id(int spec_id)
	{
		pk::building @building = get_spec_building(spec_id);
		int force_id = building.init_force;
		return force_id;
	}

	pk::force @get_spec_force(int spec_id)
	{
		int force_id = get_spec_force_id(spec_id);
		if (pk::is_valid_force_id(force_id))
		{
			return pk::get_force(force_id);
		}
		return null;
	}

	string get_spec_force_name(int spec_id)
	{
		pk::force @force = get_spec_force(spec_id);
		if (force !is null)
			return pk::get_name(force);
		return "---";
	}

	int get_spec_location_id(int spec_id)
	{
		pk::point pos = get_spec_pos(spec_id);
		int city_id = pk::get_city_id(pos);
		return city_id;
	}

	pk::city @get_spec_city(int spec_id)
	{
		return pk::get_city(get_spec_location_id(spec_id));
	}

	string get_spec_city_name(int spec_id)
	{
		pk::city @city = get_spec_city(spec_id);
		if (city !is null)
			return pk::get_name(city);
		return "---";
	}

	array<int16> get_district_able_spec_int16(pk::district @district, bool empty = false)
	{
		array<int16> temp;
		for (int16 i = 0; i < ch::get_spec_end(); ++i)
		{
			pk::point pos0 = ch::get_spec_pos(i);
			pk::building @building0 = pk::get_building(pos0);
			int district_id = district.get_id();
			if (building0 is null)
				continue;
			// 建筑无军团id，所以下方判断不可行，应该根据城市来
			// if (building0.get_district_id() != district_id)
			//	continue;
			if (empty)
			{
				auto spec_t = ch::get_spec_p(i);
				if (spec_t.person != -1)
					continue;
				if (pk::enemies_around(building0))
					continue;
			}
			int city_id = pk::get_city_id(pos0);
			pk::city @location_city = pk::get_city(city_id);
			if (!pk::is_alive(location_city) or location_city.get_district_id() != district_id)
				continue; // 排除非己方城市所属，避免前线县城管理
			temp.insertLast(i);
		}
		return temp;
	}

	array<int16> get_force_able_spec_int16(pk::force @force, bool empty = false)
	{
		array<int16> temp;
		for (int16 i = 0; i < ch::get_spec_end(); ++i)
		{
			pk::point pos0 = ch::get_spec_pos(i);
			pk::building @building0 = pk::get_building(pos0);
			int force_id = force.get_id();
			if (building0 is null)
				continue;
			if (building0.get_force_id() != force_id)
				continue;
			if (empty)
			{
				auto spec_t = ch::get_spec_p(i);
				if (spec_t.person != -1)
					continue;
				if (pk::enemies_around(building0))
					continue;
			}
			int city_id = pk::get_city_id(pos0);
			pk::city @location_city = pk::get_city(city_id);
			if (!pk::is_alive(location_city) or location_city.get_force_id() != force_id)
				continue; // 排除非己方城市所属，避免前线县城管理
			temp.insertLast(i);
		}
		return temp;
	}

	array<int16> get_base_able_spec_int16(pk::building @building, bool empty = false)
	{
		array<int16> temp;
		for (int j = 0; j < 最大城市县城数; ++j)
		{
			int spec_id = ch::get_base_spec(building.get_id(), j);
			if (ch::is_valid_spec_id(spec_id))
			{
				auto spec_t = ch::get_spec_p(spec_id);
				int person_id = spec_t.person;

				if (spec_t.person == -1 and pk::get_building(ch::to_building_id(spec_id)).get_force_id() == building.get_force_id())
				{
					int building_id = ch::to_building_id(spec_id);
					pk::building @spec = pk::get_building(building_id);

					temp.insertLast(spec_id);
				}
			}
		}
		return temp;
	}

	array<int16> get_city_able_spec_int16(pk::city @city, bool empty = false)
	{
		array<int16> temp;
		for (int16 i = 0; i < ch::get_spec_end(); ++i)
		{
			pk::point pos0 = ch::get_spec_pos(i);
			pk::building @building0 = pk::get_building(pos0);
			if (building0 is null)
				continue;
			if (building0.get_force_id() != city.get_force_id())
				continue;
			if (empty)
			{
				auto spec_t = ch::get_spec_p(i);
				if (spec_t.person != -1)
					continue;
			}
			int city_id = pk::get_city_id(pos0);
			if (city.get_id() != city_id)
				continue;
			temp.insertLast(i);
		}
		return temp;
	}

	array<int16> get_force_no_belong_city_able_spec_int16(pk::force @force)
	{
		array<int16> temp;
		for (int16 i = 0; i < ch::get_spec_end(); ++i)
		{
			pk::point pos0 = ch::get_spec_pos(i);
			pk::building @building0 = pk::get_building(pos0);
			int force_id = force.get_id();
			if (building0 is null)
				continue;
			if (building0.get_force_id() != force_id)
				continue;
			int city_id = pk::get_city_id(pos0);
			pk::city @location_city = pk::get_city(city_id);
			if (pk::is_alive(location_city) and location_city.get_force_id() != force_id)
				temp.insertLast(i);
		}
		return temp;
	}

	void set_person_weapon(int person_id, int weapon_id)
	{
		if (!pk::is_valid_person_id(person_id))
			return;
		pk::set_person_weapon(person_id, weapon_id);
		ch::get_person_p(person_id).weapon_id = weapon_id;
	}

	void set_person_horse(int person_id, int horse_id)
	{
		if (!pk::is_valid_person_id(person_id))
			return;
		pk::set_person_horse(person_id, horse_id);
		ch::get_person_p(person_id).horse_id = horse_id;
	}

	bool get_auto_affairs_status()
	{
		if (ch::get_set_p(0).get_mod_set(自动内政扩展_开关) != pk::get_auto_affairs_status())
		{
			pk::set_auto_affairs(ch::get_set_p(0).get_mod_set(自动内政扩展_开关));
		}
		return ch::get_set_p(0).get_mod_set(自动内政扩展_开关);
	}

	bool get_auto_affairs_status(pk::building @building)
	{
		if (building.get_id() >= 据点_末)
			return false;
		if (ch::get_set_p(0).get_mod_set(自动内政扩展_开关) != pk::get_auto_affairs_status())
		{
			pk::set_auto_affairs(ch::get_set_p(0).get_mod_set(自动内政扩展_开关));
		}
		bool result = ch::get_set_p(0).get_mod_set(自动内政扩展_开关);
		if (building !is null and building.is_player() and !result)
		{
			result = !pk::is_player_controlled(building);
		}

		return building.is_player() ? result : true;
	}

	void set_auto_affairs(bool value)
	{
		pk::set_auto_affairs(value);
		ch::get_set_p(0).set_mod_set(自动内政扩展_开关, value);
	}

	void toggle_auto_affairs()
	{
		ch::get_set_p(0).set_mod_set(自动内政扩展_开关, ch::get_set_p(0).get_mod_set(自动内政扩展_开关));
		pk::set_auto_affairs(!ch::get_set_p(0).get_mod_set(自动内政扩展_开关));
	}

	void set_interior_land(int city_id)
	{
		if (!pk::is_valid_city_id(city_id))
			return;
		int level = ch::get_base_p(city_id).city_level;
		if (level == 0)
			return;
		// 内政用地升级[city_id][level - 1][];
		for (int i = 1; i <= level; ++i)
		{
			set_interior_land(city_id, i);
		}
	}

	void set_interior_land(int city_id, int level)
	{
		if (level > 0 and level <= 4)
		{
			// int population = ch::get_base_p(city_id).population;

			// 内政用地升级[city_id][level - 1][];
			for (int j = 0; j < 2; ++j)
			{
				int index = 2 * j;
				pk::point pos1;
				if (pk::is_new_map())
				{
					pos1 = pk::point(内政用地升级2[city_id][level - 1][index], 内政用地升级2[city_id][level - 1][index + 1]);
				}
				else
				{
					pos1 = pk::point(内政用地升级[city_id][level - 1][index], 内政用地升级[city_id][level - 1][index + 1]);
				}
				int result = pk::add_interior_land(pos1);
				// 如果此地兵舍，厩舍，锻造厂，需刷新计数-----实际上是city_dev的building信息没更新，另外，如果城市人口减少导致内政用地减少，此信息目前只能在读档后更新
				// if (true)
				// pk::trace(city_id + ':' + pk::get_new_base_name(city_id) + " => level:" + (level - 1) + ";x:" + pos1.x + ",y:" + pos1.y + ",result:" + result + "index:" + index);
			}
		}
	}

	int get_city_level(int city_id)
	{
		int population = ch::get_base_p(city_id).population;
		int level = 0;
		if (population > 四级城市阈值)
			level = 4;
		else if (population > 三级城市阈值)
			level = 3;
		else if (population > 二级城市阈值)
			level = 2;
		else if (population > 一级城市阈值)
			level = 1;
		return level;
	}

	string get_level_desc(int level, bool encode = true)
	{
		string desc = "";
		switch (level)
		{
			case 0:
				desc = "\x1b[31x微\x1b[0x";
				break;
			case 1:
				desc = "小";
				break;
			case 2:
				desc = "\x1b[18x中\x1b[0x";
				break;
			case 3:
				desc = "\x1b[24x大\x1b[0x";
				break;
			case 4:
				desc = "\x1b[27x巨\x1b[0x";
				break;
			default:
				break;
		}

		if (encode)
			return pk::encode(desc);
		return desc;
	}

	uint32 get_level_requred_pop(int level)
	{
		if (level == 1)
			return 一级城市阈值;
		else if (level == 2)
			return 二级城市阈值;
		else if (level == 3)
			return 三级城市阈值;
		else if (level == 4)
			return 四级城市阈值;
		return 0;
	}

	uint32 get_citylevel_pop_max(int level)
	{
		// 问题在于，这样是否很难达到上限？满足扩建标准
		if (level == 0)
			return 一级城市阈值;
		else if (level == 1)
			return 二级城市阈值;
		else if (level == 2)
			return 三级城市阈值;
		else if (level == 3)
			return 四级城市阈值;
		else if (level == 4)
			return 城市人口极限阈值;
		return 0;
	}

	int get_current_period(pk::force @force)
	{
		int period = 0;
		// 目前考虑不管金粮兵装，只管实在的战力，即城数，武将数，兵力数
		int c_months = pk::get_elapsed_months();
		int c_city_count = pk::get_city_count(force);
		int c_troops = pk::get_troops(force);
		// int c_gold = ch::get_force_gold(force);
		// int c_food = ch::get_force_food(force);
		// int c_weapon =  ch::get_force_weapon(force);
		int c_person_count = ch::get_force_person_count(force);

		if (c_months > 24 and (c_city_count > 1 or c_person_count > 20 or c_troops > 60000))
			period = 1; // 对应3队2w
		// 超额完成时提前进入下一阶段
		if (c_city_count > 1 and c_person_count > 20 and c_troops > 60000)
			period = 1;
		if (c_months > 36 and (c_city_count > 3 or c_troops > 150000))
			period = 2; // 对应1贼窝5队，约4万兵
		if (c_months > 96 and (c_city_count > 5 or c_troops > 300000))
			period = 3; // 对应2贼窝10队，约8万兵
		if (c_city_count > 5 and c_troops > 300000 and c_person_count > 80)
			period = 3; // 对应2贼窝10队，约8万兵
		if (c_months > 240 and (c_city_count > 15 or c_troops > 800000))
			period = 4; // 对应3贼窝15队，约15万兵
		if (c_city_count > 15 and c_troops > 800000 and c_person_count > 150)
			period = 4; // 对应3贼窝15队，约15万兵
		// pk::trace(pk::format("经过月份：{}，城市数：{}，兵力：{}，武将数：{}，所处阶段：{}", c_months, c_city_count, c_troops, c_person_count, period));
		return period;
	}

	int get_current_period(int force_id)
	{
		pk::force @force = pk::get_force(force_id);
		if (!pk::is_alive(force))
			return 0;
		return get_current_period(force);
	}

	bool is_target_item_id(int item_id)
	{
		if (item_id < 0)
			return false;
		if (item_id > 414)
			return false;
		if (item_id > 76 and item_id < 100)
			return false;
		if (item_id > 155 and item_id < 200)
			return false;
		if (item_id > 240 and item_id < 300)
			return false;
		if (item_id > 328 and item_id < 370)
			return false;
		if (item_id > 373 and item_id < 385)
			return false;
		if (item_id > 389 and item_id < 400)
			return false;
		return true;
	}

	string get_level_string(int level)
	{
		string level_name;
		switch (level)
		{
			case 0:
				level_name = "微";
				break;
			case 1:
				level_name = "小";
				break;
			case 2:
				level_name = "中";
				break;
			case 3:
				level_name = "大";
				break;
			case 4:
				level_name = "巨";
				break;
		}
		return level_name;
	}

	void set_unit_action_done(pk::unit @unit)
	{
		unit.action_done = true;
		if (int(pk::option["San11Option.EnableInfiniteAction"]) != 0)
			unit.action_done = false;
	}

	/*
	const int 据点AI_开发 = 1;
	const int 据点AI_征兵 = 2;
	const int 据点AI_生产 = 3;
	const int 据点AI_巡察 = 4;
	const int 据点AI_交易 = 5; // ?
	const int 据点AI_训练 = 6;
	const int 据点AI_防御 = 7;
	const int 据点AI_攻击 = 8;
	const int 据点AI_设置 = 9;
	const int 据点AI_关卡运输 = 10; // 都市关卡间运输도시 관문 간 수송?
	const int 据点AI_都市运输 = 11; // 都市间运输도시 간 수송
	const int 据点AI_移动 = 12;
	const int 据点AI_召唤 = 13;
	const int 据点AI_人才探索 = 14;
	const int 据点AI_武将登用 = 15;
	const int 据点AI_褒奖 = 16;
	const int 据点AI_二虎竞食 = 17;
	const int 据点AI_驱虎吞狼 = 18;
	const int 据点AI_流言 = 19;
	const int 据点AI_他势力武将登用 = 20;
	const int 据点AI_拆除 = 21;
	const int 据点AI_计略 = 22;
	const int 据点AI_最小人才探索 = 23; // 武将 수가 难易度 값 不足时(预计失败时无条件不做). 인공지능.xml 참고 / 무장 수가 난이도 값 미만일 때만(실패 예상 시 무조건 안함). 인공지능.xml 참고
	const int 据点AI_最小武将登用 = 24; // 무장 수가 난이도 값 미만일 때만(성공 예상 시 무조건 시도). 인공지능.xml 참고
	const int 据点AI_最小他势力武将登用 = 25; // 무장 수가 3명 미만일 때만. 인공지능.xml 참고
	const int 据点AI_交易2 = 26; // ?
	const int 据点AI_吸收合并 = 27;
		*/

	string get_cmd_name(int cmd)
	{
		string cmd_name;
		switch (cmd)
		{
			case 1:
				cmd_name = "据点AI_开发 ";
				break;
			case 2:
				cmd_name = "据点AI_征兵 ";
				break;
			case 3:
				cmd_name = "据点AI_生产 ";
				break;
			case 4:
				cmd_name = "据点AI_巡察 ";
				break;
			case 5:
				cmd_name = "据点AI_交易 ";
				break;
			case 6:
				cmd_name = "据点AI_训练 ";
				break;
			case 7:
				cmd_name = "据点AI_防御 ";
				break;
			case 8:
				cmd_name = "据点AI_攻击 ";
				break;
			case 9:
				cmd_name = "据点AI_设置 ";
				break;
			case 10:
				cmd_name = "据点AI_关卡运输 ";
				break;
			case 11:
				cmd_name = "据点AI_都市运输 ";
				break;
			case 12:
				cmd_name = "据点AI_移动 ";
				break;
			case 13:
				cmd_name = "据点AI_召唤 ";
				break;
			case 14:
				cmd_name = "据点AI_人才探索 ";
				break;
			case 15:
				cmd_name = "据点AI_武将登用 ";
				break;
			case 16:
				cmd_name = "据点AI_褒奖 ";
				break;
			case 17:
				cmd_name = "据点AI_二虎竞食 ";
				break;
			case 18:
				cmd_name = "据点AI_驱虎吞狼 ";
				break;
			case 19:
				cmd_name = "据点AI_流言 ";
				break;
			case 20:
				cmd_name = "据点AI_他势力武将登用 ";
				break;
			case 21:
				cmd_name = "据点AI_拆除 ";
				break;
			case 22:
				cmd_name = "据点AI_计略 ";
				break;
			case 23:
				cmd_name = "据点AI_最小人才探索 ";
				break;
			case 24:
				cmd_name = "据点AI_最小武将登用 ";
				break;
			case 25:
				cmd_name = "据点AI_最小他势力武将登用 ";
				break;
			case 26:
				cmd_name = "据点AI_交易2 ";
				break;
			case 27:
				cmd_name = "据点AI_吸收合并 ";
				break;
			case 30:
				cmd_name = "据点AI_计略破坏  ";
				break;
			case 31:
				cmd_name = "据点AI_计略鼓舞  ";
				break;
			case 32:
				cmd_name = "据点AI_计略扰乱  ";
				break;
			case 33:
				cmd_name = "据点AI_计略攻心  ";
				break;
			case 34:
				cmd_name = "据点AI_计略援军  ";
				break;
			case 35:
				cmd_name = "据点AI_计略镇静  ";
				break;
			case 36:
				cmd_name = "据点AI_计略伪报  ";
				break;
			case 37:
				cmd_name = "据点AI_计略火攻  ";
				break;
			case 38:
				cmd_name = "据点AI_计略调查  ";
				break;
			case 39:
				cmd_name = "据点AI_计略刺杀  ";
				break;
			case 40:
				cmd_name = "据点AI_计略奇袭攻具  ";
				break;
			case 41:
				cmd_name = "据点AI_计略待劳  ";
				break;
			case 50:
				cmd_name = "据点AI_募兵  ";
				break;
			case 51:
				cmd_name = "据点AI_民兵  ";
				break;
			case 52:
				cmd_name = "据点AI_招募雇佣兵  ";
				break;
			case 53:
				cmd_name = "据点AI_护送俘虏  ";
				break;
			case 54:
				cmd_name = "据点AI_屏障建设  ";
				break;
			case 55:
				cmd_name = "据点AI_城墙维修  ";
				break;
			case 56:
				cmd_name = "据点AI_部队奇袭攻具  ";
				break;
			case 57:
				cmd_name = "据点AI_支援关卡  ";
				break;
			case 60:
				cmd_name = "据点AI_紧急动员  ";
				break;
			case 100:
				cmd_name = "据点AI_联合军出征  ";
				break;
			case 101:
				cmd_name = "据点AI_县城管理  ";
				break;
			case 102:
				cmd_name = "据点AI_解除县城管理  ";
				break;
			case 200:
				cmd_name = "据点AI_末  ";
				break;
			default:
				cmd_name = "??";
				break;
		}
		return cmd_name;
	}

	uint get_stat_color(int type)
	{
		switch (type)
		{
			case 0:
				return 0xffffabc1;
			case 1:
				return 0xffc49df5;
			case 2:
				return 0xffd2d25f;
			case 3:
				return 0xff56dbaf;
			case 4:
				return 0xff80d1fe;
		}
		return 0xffffffff;
	}

	string get_unit_stat_name(int stat_type)
	{
		/*
		string color_text = "";
		switch (stat_type)
		{
		case 部队能力_攻击:
			color_text = "\x1b[27x"; break;
		case 部队能力_防御:
			color_text = "\x1b[27x"; break;
		case 部队能力_智力:
			color_text = "\x1b[18x"; break;
		case 部队能力_建设:
			color_text = "\x1b[28x"; break;
		case 部队能力_移动:
			color_text = "\x1b[32x"; break;
		}*/
		switch (stat_type)
		{
			case 0:
				return "攻击";
			case 1:
				return "防御";
			case 2:
				return "智力";
			case 3:
				return "建设";
			case 4:
				return "移动";
		}
		return "";
	}

	string get_stat_name(int stat_type, bool color = false)
	{

		switch (stat_type)
		{
			case 武将能力_统率:
				return "统率";
			case 武将能力_武力:
				return "武力";
			case 武将能力_智力:
				return "智力";
			case 武将能力_政治:
				return "政治";
			case 武将能力_魅力:
				return "魅力";
		}
		return "";
	}

	string get_tekisei_name(int tekisei_type)
	{
		switch (tekisei_type)
		{
			case 兵种_枪兵:
				return "枪兵";
			case 兵种_戟兵:
				return "戟兵";
			case 兵种_弩兵:
				return "弩兵";
			case 兵种_骑兵:
				return "骑兵";
			case 兵种_兵器:
				return "兵器";
			case 兵种_水军:
				return "水军";
		}
		return "";
	}

	bool is_near_building(pk::unit @src_unit)
	{
		// 或者城市用get_city_id()
		pk::point pos = src_unit.pos;
		int src_force_id = src_unit.get_force_id();
		int area_city_id = pk::get_city_id(pos);
		if (pk::get_city(area_city_id).get_force_id() == src_force_id)
			return true;
		array<pk::point> range_pos_arr = pk::range(pos, 1, 3); // 直接搜索3格，因为港关是3格，排除城市，因为城市范围太大
		for (int arr_index = 0; arr_index < int(range_pos_arr.length); arr_index++)
		{
			pk::point range_pos = range_pos_arr[arr_index];
			if (!pk::is_valid_pos(range_pos))
				continue;
			pk::hex @hex = pk::get_hex(range_pos);
			if (!hex.has_building)
				continue;
			pk::building @building0 = pk::get_building(range_pos);

			if ((building0.facility == 设施_港口 or building0.facility == 设施_关卡) and building0.get_force_id() == src_force_id)
			{
				if (pk::get_distance(pos, range_pos) <= 3)
					return true;
			}
			if ((building0.facility == 设施_阵 or building0.facility == 设施_砦 or building0.facility == 设施_城塞 or building0.facility == 设施_箭楼 or building0.facility == 设施_连弩楼 or building0.facility == 设施_投石台) and building0.get_force_id() == src_force_id)
			{
				if (pk::get_distance(pos, range_pos) <= 2)
					return true;
			}
		}

		return false;
	}

	bool is_new_face(int person_id)
	{
		pk::person @person = pk::get_person(person_id);
		if (pk::is_alive(person))
		{
			int face_id = pk::get_person(person_id).face;
			if (face_id > 1999 and face_id <= 2132)
				return true; // 头像编号重排后，调整此函数
			else if (face_id > 2149 and face_id <= 2182)
				return true;
		}
		return false;
	}

	// 作为对话框背景模板，可随意调节大小
	pk::button @create_bg_dialog(pk::dialog @dialog, pk::size size, string& title)
	{
		pk::assert(size.width >= 301);
		pk::assert(size.height >= 16);

		pk::widget @w = dialog.create_sprite(70); //(70);//70是半透明
		w.set_pos(12, 54);
		w.set_size(size);
		@w = dialog.create_sprite(499); //(70);//70是半透明
		w.set_pos(12, 54);
		w.set_size(size);

		@w = dialog.create_image(320);
		// dialog.add_titlebar(w.get_id(), 320);

		pk::text @t = dialog.create_text();
		t.set_pos(40, 22);
		t.set_size(pk::get_text_size(FONT_BIG, title));
		t.set_text(title);
		t.set_text_font(FONT_BIG);

		@w = dialog.create_sprite(430);
		// dialog.add_titlebar(w.get_id(), 430);
		w.set_pos(284, 36);
		w.set_size(size.width - 301, w.get_size().height);

		@w = dialog.create_image(321);
		w.set_pos(size.width - 17, 36);
		// dialog.add_titlebar(w.get_id(), 320);

		@w = dialog.create_sprite(432);
		w.set_pos(5, 64);
		w.set_size(w.get_size().width, size.height - 16);

		@w = dialog.create_sprite(431);
		w.set_pos(size.width + 11, 64);
		w.set_size(w.get_size().width, size.height - 16);

		@w = dialog.create_image(323);
		w.set_pos(5, size.height + 48);

		@w = dialog.create_sprite(433);
		w.set_pos(257, size.height + 48);
		w.set_size(size.width - 298, w.get_size().height);

		@w = dialog.create_image(322);
		w.set_pos(size.width - 41, size.height + 48);

		pk::button @ok_button = dialog.create_button(172);
		ok_button.set_pos(27, size.height + 58);
		ok_button.set_text(pk::encode("决定"));

		dialog.resize();

		return ok_button;
	}

	void remove_idle_person(pk::ai_context @context, pk::list<pk::person @> list)
	{
		if (list.count == 0)
			return;
		for (int i = 0; i < list.count; ++i)
		{
			int index = context.idle_person.index_of(list[i]);
			if (index > -1 and index < context.idle_person.count)
			{
				context.idle_person.remove_at(index); //
			}
		}
	}

	// 设置武将伤病
	bool set_person_wound(pk::person @person, int wound_type, bool skill_buff = true, pk::unit @person_unit = null)
	{
		if (person is null or !pk::is_alive(person) or wound_type >= 伤病_末)
			return false;
		bool result = true;
		if (skill_buff)
		{
			if (has_skill(person, 特技_幸运))
				result = false;
			if (pk::is_unitize(person))
			{
				pk::unit @unit = person_unit is null ? pk::get_unit(person.get_pos()) : @person_unit;
				if (has_skill(unit, 特技_护卫) and !has_skill(person, 特技_幸运))
					result = false;
			}
		}
		if (result)
		{
			person.shoubyou = wound_type;
			person.update();
		}
		return result;
	}

	bool is_auto_affairs_role(int role)
	{
		return role > 0 and role <= 7;
	}

	bool is_siege_unit(pk::unit@ unit)
	{
		int weapon_id = pk::get_ground_weapon_id(unit);
		if (weapon_id >= 兵器_冲车 and weapon_id <= 兵器_木兽) return true;
		return false;
	}

	//科技提供的权重最大为3,也就是一级适性的权重.
    int get_tech_score(pk::force @force, int weapon_id)
    {
        if (force is null)
            return 0;
        switch (weapon_id)
        {
            case 兵器_剑:
                return 0;
            case 兵器_枪:
                {
                    if (pk::has_tech(force, 技巧_精锐枪兵))
                        return 3;
                    else if (pk::has_tech(force, 技巧_奇袭))
                        return 2;
                    else if (pk::has_tech(force, 技巧_兵粮袭击))//兵粮袭击不能增强骑兵作战能力
                        return 1;
                    else if (pk::has_tech(force, 技巧_枪兵锻练))
                        return 1;
                    else
                        return 0;
                }
            case 兵器_戟:
                {
                    if (pk::has_tech(force, 技巧_精锐戟兵))
                        return 3;
                    else if (pk::has_tech(force, 技巧_大盾))
                        return 2;
                    else if (pk::has_tech(force, 技巧_矢盾))//矢不能增强骑兵作战能力
                        return 1;
                    else if (pk::has_tech(force, 技巧_戟兵锻练))
                        return 1;
                    else
                        return 0;
                }
            case 兵器_弩:
                {
                    if (pk::has_tech(force, 技巧_精锐弩兵))
                        return 3;
                    else if (pk::has_tech(force, 技巧_强弩))
                        return 2;
                    else if (pk::has_tech(force, 技巧_应射)) //应射不能增强骑兵作战能力
                        return 1;
                    else if (pk::has_tech(force, 技巧_弩兵锻练))
                        return 1;
                    else
                        return 0;
                }
            case 兵器_战马:
                {
                    if (pk::has_tech(force, 技巧_精锐骑兵))
                        return 3;
                    else if (pk::has_tech(force, 技巧_骑射))  //骑射不能增强骑兵作战能力
                        return 2;
                    else if (pk::has_tech(force, 技巧_良马产出))
                        return 2;
                    else if (pk::has_tech(force, 技巧_骑兵锻练))
                        return 1;
                    else
                        return 0;
                }
            case 兵器_冲车:
                return 2;    	//由于冲车.井阑没有科技,因此很容易其他兵种有些科技就不出兵器,所以需要有默认的科技点
            case 兵器_井阑:
                return 2;
            case 兵器_投石:
                {
                    if (pk::has_tech(force, 技巧_霹雳))
                        return 4;
                    else
                        return 0;
                }
            case 兵器_木兽:
                return 3;
            case 兵器_走舸:
                return 0;
            case 兵器_楼船:
                return 2;
            case 兵器_斗舰:
                {
                    if (pk::has_tech(force, 技巧_霹雳))
                        return 4;
                    else
                        return 0;
                }
            default:
                return 0;
        }
        return 0;
    }

    // 兵装检测
    bool check_weapon_able(pk::building @building, int weapon_id)
    {
        bool 投石科技 = pk::has_tech(building, 技巧_投石开发);
        bool 木兽科技 = pk::has_tech(building, 技巧_木兽开发);

        if (weapon_id == 兵器_剑 or weapon_id == 兵器_走舸)
            return true;
        if (weapon_id == 兵器_投石 and !投石科技)
            return false;

        if (weapon_id == 兵器_木兽 and !木兽科技)
            return false;

        if (weapon_id > 兵器_战马)
        {
            if (pk::get_weapon_amount(building, weapon_id) >= 1)
                return true;
        }
        else
        {
            if (pk::get_weapon_amount(building, weapon_id) >= 6000)
                return true;
        }
        return false;
    }

	pk::widget@ create_widget(pk::dialog@ dlg, int widget_type, int tex = -1)
	{
		switch (widget_type)
		{
			case DLG_ITEM_TYPE_IMAGE:
				return dlg.create_image(tex);
			case DLG_ITEM_TYPE_SPRITE9:
			case DLG_ITEM_TYPE_SPRITE8:
			case DLG_ITEM_TYPE_SPRITE_V:
			case DLG_ITEM_TYPE_SPRITE_H:
			case DLG_ITEM_TYPE_SPRITE_T:
				return dlg.create_sprite(tex);
			case DLG_ITEM_TYPE_BUTTON1:
				return dlg.create_button(tex, 0);
			case DLG_ITEM_TYPE_TEXT:
				return dlg.create_text();
			case DLG_ITEM_TYPE_BUTTON3:
				return dlg.create_button(tex, 0);

			default:
				return null;
		}
		return null;
	}

	// 势力颜色
	void add_force_color(pk::hud_container@ hud, pk::hud@ bg, int force_id)
	{
		int method = 0;
		if (method == 0)
		{
			//Background
			pk::image_hud@ image = hud.create_image(0);
			image.set_z_order(999);
			image.set_image(pk::core_dir + "data/0328/hud-1x1.png", false); // 无效pk::core_dir + "data/dahunluan.png");
			image.set_pos(bg.get_pos());
			image.set_size(bg.get_size());
			pk::bgra32 color = pk::bgra32(force_color[force_id]);

			color.a = uint8(color.a * 0.5f);
			//pk::trace(pk::format("b:{},g:{},r:{},a:{}", color.b, color.g, color.r, color.a));
			image.set_color(color.c);
		}
		else if (method == 1)
		{
			pk::image_hud@ image = hud.create_image(0);
			image.set_z_order(999);
			image.set_image(pk::core_dir + "data/0328/hud-1x1.png", false); // 无效pk::core_dir + "data/dahunluan.png");
			auto pos = bg.get_pos();
			auto size = bg.get_size();
			pos.x = pos.x - 1;
			size.w = 4;
			image.set_pos(pos);
			image.set_size(size);
			pk::bgra32 color = pk::bgra32(force_color[force_id]);//pk::bgra32(pk::get_force_color2(force_id));
			image.set_color(color.c);
		}

	}

	bool is_neighbor_force(pk::force@ force0, pk::force@ force1)
	{	
		if (!pk::is_alive(force0) or !pk::is_alive(force1)) return false;
		int force0_id = force0.get_id();
		int force1_id = force1.get_id();
		int neighbor_building_count = ai::force_to_force_enemy_base[force0_id][force1_id];
		return neighbor_building_count > 0;
	}

	bool is_neighbor_force(int force0_id, int force1_id)
	{	
		if (!pk::is_valid_force_id(force0_id) or !pk::is_valid_force_id(force1_id)) return false;
		int neighbor_building_count = ai::force_to_force_enemy_base[force0_id][force1_id];
		return neighbor_building_count > 0;
	}

	string get_base_policy(pk::building@ building)
	{
		auto building_p = ch::get_baseIA(building.get_id());
		array<string> select_data2 = {"\x1b[16x强征兵役\x1b[0x", "\x1b[24x积极动员\x1b[0x", "\x1b[21x均衡政策\x1b[0x", "\x1b[2x安民政策\x1b[0x", "\x1b[28x休养生息\x1b[0x"};
		string building_troops_policy = "";
		if (building_p.building_policy >= 0 and building_p.building_policy < 5)
			building_troops_policy = select_data2[building_p.building_policy];

		return building_troops_policy;
	}

	/*
	检测游戏是否刚开局
	type-0: 只计算开局时间。
	type-1: 计算开局时间跟武将行动。
	 */
	bool is_begin_game(int type = 0)
	{
		bool result = pk::get_scenario().turn_counter == 0;
		if (type == 1)
		{
			for (int i = 0; i < 可用武将_末; i += 1)
			{
				pk::person@ person = pk::get_person(i);
				if (person !is null and pk::is_alive(person))
				{
					if (person.action_done) return false;
				}
			}
		}
		return result;
	}

	// 增减武将经验，增加是否动画提示
	void add_stat_exp(pk::person@ person, int type, int value, bool effect = true)
	{
		if (person is null) return ;
		if (type < 0 or type >= 武将能力_末) return ;
		if (effect) pk::add_stat_exp(person, type, value);
		else
		{
			person.stat_exp[type] = person.stat_exp[type] + value;
			person.update();
			pk::point pos = pk::get_hex_object(person.location).get_pos();
			pk::force@ force = pk::get_force(person.get_force_id());
			string msg = pk::encode(pk::format("\x1b[1x{}\x1b[0x的{}上升为{}（＋{}）了！", pk::decode(pk::get_name(person)), get_stat_name(type), person.max_stat[type], int(value / 100)));
			pk::history_log(pos, force is null ? -1 : force.color, msg);
		}
	}

	void conduct_action(pk::unit@ unit, pk::action_info& info)
	{
		pk::unit_select(unit);
		if (info.type < 8)
		{
			pk::conduct_action(info);
		}
		else if (info.type == 8)//额外加的部队菜单的动作
		{
			conduct_unit_action_8(unit, info);
		}
		pk::unit_unselect();
	}
	//////////////////////////////////////////部队指挥相关函数///////////////////////////////////////////////

	bool conduct_unit_action_8(pk::unit@ unit, pk::action_info& info)
	{
		if (info.type == 8)//在原type id上扩展
		{
			switch (info.action_id)
			{
				case UNIT_COMMAND_DISBAND:
					return conduct_action_解散(unit, info);
				case UNIT_COMMAND_MERGE:
					return  conduct_action_合并(unit, info);
				case UNIT_COMMAND_RECRUIT:
					return conduct_action_招募乡勇(unit, info);
				case UNIT_COMMAND_REPLACEMENT:
					return conduct_action_换帅(unit, info);
				case UNIT_COMMAND_FORCED_MARCH:
					return conduct_action_强行军(unit, info);
				default:
					break;
			}
		}
		return false;
	}

	bool conduct_action_解散(pk::unit@ unit, pk::action_info& info)
	{
		pk::say(pk::encode("解散部队"), pk::get_person(unit.leader));
		ch::add_troops(unit, -int(unit.troops), false, 102);//以全逃兵形式实现
		if (unit.troops <= 0)
			pk::kill(unit);
		return true;
	}

	bool conduct_action_合并(pk::unit@ unit, pk::action_info& info)
	{
		pk::unit@ target_unit = pk::get_unit(info.target_pos);

		// 执行部队的音效应该在移动后
		if (pk::is_in_screen(info.move_pos))
		{
			pk::play_se(0x39, info.move_pos);
			//pk::wait(1, 1000);
		}

		int troops_re_org = pk::min(unit.troops, (pk::get_max_troops(target_unit) - target_unit.troops));
		int energy_re_org = ((troops_re_org * unit.energy) + (target_unit.troops * target_unit.energy)) / (troops_re_org + target_unit.troops);

		int food_re_org = pk::min(unit.food, (2 * troops_re_org));


		// 执行部队的兵和粮减少
		ch::add_troops(unit, -troops_re_org, true);//我方部队减兵力
		pk::add_food(unit, -food_re_org, true);

		if (unit.troops == 0)
		{
			pk::say(pk::encode("我军部队解散."), pk::get_person(unit.leader));
			pk::kill(unit);
		}
		else
		{
			pk::say(pk::encode("兵力已达到满编制."), pk::get_person(unit.leader));
		}


		// 대상부대 병력증가
		ch::add_troops(target_unit, troops_re_org, true);//目标部队加兵力
		pk::say(pk::encode("从现在开始听我指挥"), pk::get_person(target_unit.leader));
		// 대상부대 병량증가
		pk::add_food(target_unit, food_re_org, true);
		// 대상부대 기력조정
		pk::add_energy(target_unit, (energy_re_org - target_unit.energy), true);

		// 효과 : 기력상승(보라)
		if (pk::is_in_screen(target_unit.pos))
			pk::create_effect(0x4c, target_unit.pos);

		// 행동완료
		unit.action_done = true;
		if (int(pk::option["San11Option.EnableInfiniteAction"]) != 0)
			unit.action_done = false;
		return true;
	}

	bool conduct_action_招募乡勇(pk::unit@ unit, pk::action_info& info)
	{
		int GOLD_COST_招募乡勇 = 300;//以后可以考虑直接放全局常量
		pk::unit@ target_unit = pk::get_unit(info.target_pos);

		// 실행 부대 계략 실행 음성 효과, 실행/대상부대 대화
		if (pk::is_in_screen(info.move_pos))
		{
			pk::play_voice(0x37, pk::get_person(unit.leader));  // 음성 : 진정
			pk::play_se(0x39, info.move_pos);
			pk::create_effect(0x4a, info.move_pos);  // 효과: 기력상승(빨강)
		}
		// 실행 부대 소지금 감소, 병력 회복
		pk::say(pk::encode("招募乡勇参与战斗吧!"), pk::get_person(unit.leader));
		pk::add_gold(unit, -GOLD_COST_招募乡勇, true);

		ch::add_troops(target_unit, (GOLD_COST_招募乡勇 / 40 * pk::get_person(unit.leader).stat[武将能力_魅力]), true);//治疗伤员得换一种实现形式，注意

		// 기교점수
		ch::add_tp(pk::get_force(unit.get_force_id()), 20, info.target_pos);
		// 능력경험치
		pk::add_stat_exp(unit, 武将能力_魅力, 4);
		// 공적
		pk::add_kouseki(unit, 100);

		// 행동완료
		unit.action_done = true;
		if (int(pk::option["San11Option.EnableInfiniteAction"]) != 0 and pk::is_player_controlled(unit))
			unit.action_done = false;

		return true;
	}

	bool conduct_action_换帅(pk::unit@ unit, pk::action_info& info)
	{
		// 주장/부장 리스트
		pk::person@ p0 = pk::get_person(unit.member[0]);
		pk::person@ p1 = pk::get_person(unit.member[1]);
		pk::person@ p2 = pk::get_person(unit.member[2]);

		pk::list<pk::person@> member_list;
		if (pk::is_alive(p0)) member_list.add(p0);
		if (pk::is_alive(p1)) member_list.add(p1);
		if (pk::is_alive(p2)) member_list.add(p2);

		// 지휘병력 확인
		int cmd_old = pk::get_command(p0);
		int cmd_new;

		// 무장 선택
		bool confirm = false;
		pk::list<pk::person@> leader_sel;
		int leader_id;
		pk::person@ leader;
		string leader_name;
		while (!confirm)
		{
			leader_sel = pk::person_selector(pk::encode("选择主将"), pk::encode("选择部队的主将."), member_list, 1, 1);
			if (leader_sel.count == 0)
			{
				//unit.action_done = true;
				return false; // 취소 종료
			}


			leader_id = leader_sel[0].get_id();      // 선택한 무장번호
			if (leader_id == unit.member[0])
			{
				pk::message_box(pk::encode("未变更主将"));
			}
			else
			{
				@leader = pk::get_person(leader_id);
				leader_name = pk::decode(pk::get_name(leader));
				cmd_new = pk::get_command(leader);
				confirm = pk::yes_no(pk::encode(pk::format("是否选择\x1b[1x{}\x1b[0x作为新的主将?\n(部队最高指挥兵力从\x1b[1x{}\x1b[0x变成\x1b[1x{}\x1b[0x)", leader_name, cmd_old, cmd_new)));
			}
		}

		// 주장/부장 무장ID swap
		if (leader_id == unit.member[2])
		{
			unit.member[2] = unit.member[0];
		}
		else if (leader_id == unit.member[1])
		{
			unit.member[1] = unit.member[0];
		}
		unit.member[0] = leader_id;
		unit.update();

		// 새로운 주장의 대화표시
		if (pk::is_in_screen(info.move_pos))
		{
			pk::say(pk::encode(pk::format("从现在开始由我\x1b[1x{}\x1b[0x指挥", leader_name)), leader);
		}

		// 지휘병력 초과 시 부대 병력 조정
		if (int(unit.troops) > int(cmd_new))
			ch::add_troops(unit, int(unit.troops - cmd_new), true, 102);//兵力超过减兵需要另一种模式

		// 행동완료
		unit.action_done = true;
		if (int(pk::option["San11Option.EnableInfiniteAction"]) != 0)
			unit.action_done = false;
		return true;
	}

	bool conduct_action_强行军(pk::unit@ unit, pk::action_info& info)
	{
		float MOVEMENT_强行军 = 0.6f;//以后可以考虑直接放全局常量
		pk::point dst_pos = info.target_pos;//这里得考虑下用target_pos好还是move_pos
		// 추가 이동력 설정
		int movement = int(MOVEMENT_强行军 * unit.attr.stat[部队能力_移动]);
		int cost_sum = 0;   // 총 이동 cost 더하기

		// 부대 위치 지형
		pk::hex@ hex = pk::get_hex(unit.pos);
		int terrain_id = hex.terrain;
		// 부대 병과
		int weapon_id = pk::is_water_terrain(terrain_id) ? pk::get_sea_weapon_id(unit) : pk::get_ground_weapon_id(unit);
		pk::equipment@ equipment = pk::get_equipment(weapon_id);


		// 목표지점까지 이동 경로 획득
		array<pk::point> steps;
		// 중간이동지점
		auto paths = pk::get_path(unit, unit.pos, dst_pos);

		// 중간이동지점
		for (int i = 0; i < int(paths.length); i++)
		{
			@hex = pk::get_hex(paths[i]);
			terrain_id = hex.terrain;
			weapon_id = pk::is_water_terrain(terrain_id) ? pk::get_sea_weapon_id(unit) : pk::get_ground_weapon_id(unit);
			@ equipment = pk::get_equipment(weapon_id);

			steps.insertLast(paths[i]); //중간이동지점 추가
			if (i > 0)
				cost_sum += equipment.movement_cost[terrain_id];

		}

		// 최종이동지점
		@hex = pk::get_hex(dst_pos);
		terrain_id = hex.terrain;
		weapon_id = pk::is_water_terrain(terrain_id) ? pk::get_sea_weapon_id(unit) : pk::get_ground_weapon_id(unit);
		@ equipment = pk::get_equipment(weapon_id);

		steps.insertLast(dst_pos);  //최종이동지점 추가
		cost_sum += equipment.movement_cost[terrain_id];

		// 부대 강행군 실행
		if (steps.length != 0)
		{
			// 실행 부대 계략 실행 음성 효과
			if (pk::is_in_screen(info.move_pos))
			{
				//pk::play_se(0x39, src_pos_);
				//pk::create_effect(0x3a, src_pos_);
				switch (pk::rand(2))
				{
					case 0: pk::play_voice(0x1A, pk::get_person(unit.leader)); break; // 음성 : 전투_이동
					case 1: pk::play_voice(0x1B, pk::get_person(unit.leader)); break; // 음성 : 전투_이동
				}
			}

			pk::say(pk::encode("加紧赶路!"), pk::get_person(unit.leader));

			// [이동경로상 이동 cost] x 50%] 만큼 기력 소모
			pk::add_energy(unit, -int(0.50f * cost_sum), true);
			// 병력의 5% x [이동경로상 이동 cost]/[총 이동력] 만큼 병력 이탈
			ch::add_troops(unit, -int(0.05f * unit.troops * cost_sum / movement), true, 101);//强行军损伤的伤兵和逃兵可能得其他模式

			if (unit.type == 部队类型_运输)
			{
				//损耗各类物资
				//金
				if (unit.gold > 1) pk::add_gold(unit, -int(0.1f * unit.gold), true);
				//兵粮
				if (unit.food > 1) pk::add_food(unit, -int(0.1f * unit.food), true);
				//各类兵器
				for (int i = 0; i < 兵器_末; ++i)
				{
					if (unit.stock[i].amount > 1) unit.stock[i].amount -= int(0.1f * unit.stock[i].amount);
				}
			}
			pk::move(unit, steps); // 전체경로 일괄이동

		}

		// 행동완료
		unit.action_done = true;
		if (int(pk::option["San11Option.EnableInfiniteAction"]) != 0)
			unit.action_done = false;


		return true;
	}


	// pk::event::debate(kunshu_, selected_person_, pk::is_player_controlled(kunshu_), false, false, true).first;

	const array<array<array<int>>> 内政用地升级 = {
  {/*辽东 */	{/*级别1*//*x*/179,/*y*/19,/*级别1*//*x*/180,/*y*/20},	{/*级别2*//*x*/180,/*y*/21,/*级别2*//*x*/179,/*y*/20},	{/*级别3*//*x*/178,/*y*/20,/*级别3*//*x*/177,/*y*/19},	{/*级别4*//*x*/176,/*y*/20,/*级别4*//*x*/175,/*y*/20}},
  {/*北平 */	{/*级别1*//*x*/150,/*y*/30,/*级别1*//*x*/150,/*y*/27},	{/*级别2*//*x*/149,/*y*/26,/*级别2*//*x*/148,/*y*/26},	{/*级别3*//*x*/147,/*y*/26,/*级别3*//*x*/146,/*y*/27},	{/*级别4*//*x*/150,/*y*/26,/*级别4*//*x*/149,/*y*/25}},
  {/*蓟 */	{/*级别1*//*x*/126,/*y*/13,/*级别1*//*x*/130,/*y*/13},	{/*级别2*//*x*/131,/*y*/12,/*级别2*//*x*/130,/*y*/12},	{/*级别3*//*x*/131,/*y*/14,/*级别3*//*x*/132,/*y*/13},	{/*级别4*//*x*/130,/*y*/14,/*级别4*//*x*/131,/*y*/13}},
  {/*渤海 */	{/*级别1*//*x*/141,/*y*/31,/*级别1*//*x*/140,/*y*/33},	{/*级别2*//*x*/143,/*y*/35,/*级别2*//*x*/142,/*y*/35},	{/*级别3*//*x*/142,/*y*/36,/*级别3*//*x*/140,/*y*/31},	{/*级别4*//*x*/140,/*y*/32,/*级别4*//*x*/139,/*y*/31}},
  {/*平原 */	{/*级别1*//*x*/123,/*y*/56,/*级别1*//*x*/124,/*y*/57},	{/*级别2*//*x*/125,/*y*/57,/*级别2*//*x*/126,/*y*/58},	{/*级别3*//*x*/123,/*y*/55,/*级别3*//*x*/124,/*y*/56},	{/*级别4*//*x*/125,/*y*/56,/*级别4*//*x*/126,/*y*/57}},
  {/*太原 */	{/*级别1*//*x*/78,/*y*/31,/*级别1*//*x*/78,/*y*/32},	{/*级别2*//*x*/78,/*y*/33,/*级别2*//*x*/78,/*y*/34},	{/*级别3*//*x*/77,/*y*/31,/*级别3*//*x*/77,/*y*/32},	{/*级别4*//*x*/77,/*y*/33,/*级别4*//*x*/77,/*y*/34}},
  {/*邺 */	{/*级别1*//*x*/118,/*y*/42,/*级别1*//*x*/118,/*y*/41},	{/*级别2*//*x*/118,/*y*/40,/*级别2*//*x*/118,/*y*/39},	{/*级别3*//*x*/118,/*y*/38,/*级别3*//*x*/117,/*y*/37},	{/*级别4*//*x*/116,/*y*/38,/*级别4*//*x*/115,/*y*/38}},
  {/*北海 */	{/*级别1*//*x*/170,/*y*/47,/*级别1*//*x*/170,/*y*/48},	{/*级别2*//*x*/170,/*y*/49,/*级别2*//*x*/170,/*y*/50},	{/*级别3*//*x*/169,/*y*/46,/*级别3*//*x*/169,/*y*/47},	{/*级别4*//*x*/169,/*y*/48,/*级别4*//*x*/169,/*y*/49}},
  {/*广陵 */	{/*级别1*//*x*/182,/*y*/96,/*级别1*//*x*/182,/*y*/95},	{/*级别2*//*x*/182,/*y*/94,/*级别2*//*x*/182,/*y*/93},	{/*级别3*//*x*/181,/*y*/96,/*级别3*//*x*/181,/*y*/95},	{/*级别4*//*x*/181,/*y*/94,/*级别4*//*x*/181,/*y*/93}},
  {/*下邳 */	{/*级别1*//*x*/167,/*y*/86,/*级别1*//*x*/168,/*y*/87},	{/*级别2*//*x*/169,/*y*/87,/*级别2*//*x*/170,/*y*/88},	{/*级别3*//*x*/171,/*y*/88,/*级别3*//*x*/172,/*y*/89},	{/*级别4*//*x*/167,/*y*/87,/*级别4*//*x*/168,/*y*/88}},
  {/*寿春 */	{/*级别1*//*x*/148,/*y*/101,/*级别1*//*x*/149,/*y*/101},	{/*级别2*//*x*/150,/*y*/102,/*级别2*//*x*/151,/*y*/101},	{/*级别3*//*x*/152,/*y*/101,/*级别3*//*x*/153,/*y*/101},	{/*级别4*//*x*/150,/*y*/103,/*级别4*//*x*/151,/*y*/102}},
  {/*濮阳 */	{/*级别1*//*x*/142,/*y*/68,/*级别1*//*x*/143,/*y*/68},	{/*级别2*//*x*/144,/*y*/68,/*级别2*//*x*/143,/*y*/67},	{/*级别3*//*x*/141,/*y*/67,/*级别3*//*x*/142,/*y*/67},	{/*级别4*//*x*/144,/*y*/67,/*级别4*//*x*/143,/*y*/66}},
  {/*陈留 */	{/*级别1*//*x*/110,/*y*/76,/*级别1*//*x*/113,/*y*/72},	{/*级别2*//*x*/113,/*y*/73,/*级别2*//*x*/112,/*y*/73},	{/*级别3*//*x*/111,/*y*/72,/*级别3*//*x*/110,/*y*/73},	{/*级别4*//*x*/110,/*y*/74,/*级别4*//*x*/110,/*y*/75}},
  {/*许昌 */	{/*级别1*//*x*/103,/*y*/90,/*级别1*//*x*/104,/*y*/91},	{/*级别2*//*x*/104,/*y*/90,/*级别2*//*x*/103,/*y*/89},	{/*级别3*//*x*/102,/*y*/93,/*级别3*//*x*/105,/*y*/90},	{/*级别4*//*x*/105,/*y*/91,/*级别4*//*x*/102,/*y*/94}},
  {/*汝南 */	{/*级别1*//*x*/114,/*y*/111,/*级别1*//*x*/114,/*y*/112},	{/*级别2*//*x*/114,/*y*/113,/*级别2*//*x*/115,/*y*/110},	{/*级别3*//*x*/115,/*y*/111,/*级别3*//*x*/115,/*y*/112},	{/*级别4*//*x*/116,/*y*/111,/*级别4*//*x*/116,/*y*/112}},
  {/*洛阳 */	{/*级别1*//*x*/78,/*y*/79,/*级别1*//*x*/76,/*y*/78},	{/*级别2*//*x*/77,/*y*/78,/*级别2*//*x*/75,/*y*/78},	{/*级别3*//*x*/81,/*y*/73,/*级别3*//*x*/83,/*y*/74},	{/*级别4*//*x*/83,/*y*/75,/*级别4*//*x*/82,/*y*/74}},
  {/*宛 */	{/*级别1*//*x*/82,/*y*/94,/*级别1*//*x*/81,/*y*/98},	{/*级别2*//*x*/84,/*y*/94,/*级别2*//*x*/83,/*y*/94},	{/*级别3*//*x*/81,/*y*/95,/*级别3*//*x*/81,/*y*/96},	{/*级别4*//*x*/82,/*y*/98,/*级别4*//*x*/81,/*y*/97}},
  {/*长安 */	{/*级别1*//*x*/51,/*y*/69,/*级别1*//*x*/51,/*y*/70},	{/*级别2*//*x*/51,/*y*/71,/*级别2*//*x*/52,/*y*/69},	{/*级别3*//*x*/52,/*y*/70,/*级别3*//*x*/52,/*y*/71},	{/*级别4*//*x*/52,/*y*/72,/*级别4*//*x*/48,/*y*/74}},
  {/*朔方 */	{/*级别1*//*x*/37,/*y*/5,/*级别1*//*x*/37,/*y*/6},	{/*级别2*//*x*/37,/*y*/7,/*级别2*//*x*/37,/*y*/8},	{/*级别3*//*x*/36,/*y*/7,/*级别3*//*x*/36,/*y*/8},	{/*级别4*//*x*/36,/*y*/9,/*级别4*//*x*/41,/*y*/6}},
  {/*安定 */	{/*级别1*//*x*/29,/*y*/47,/*级别1*//*x*/29,/*y*/48},	{/*级别2*//*x*/28,/*y*/47,/*级别2*//*x*/28,/*y*/48},	{/*级别3*//*x*/28,/*y*/49,/*级别3*//*x*/27,/*y*/47},	{/*级别4*//*x*/27,/*y*/48,/*级别4*//*x*/26,/*y*/48}},
  {/*天水 */	{/*级别1*//*x*/3,/*y*/67,/*级别1*//*x*/4,/*y*/69},	{/*级别2*//*x*/4,/*y*/68,/*级别2*//*x*/4,/*y*/67},	{/*级别3*//*x*/4,/*y*/66,/*级别3*//*x*/4,/*y*/64},	{/*级别4*//*x*/4,/*y*/63,/*级别4*//*x*/4,/*y*/62}},
  {/*武威 */	{/*级别1*//*x*/2,/*y*/26,/*级别1*//*x*/2,/*y*/27},	{/*级别2*//*x*/2,/*y*/28,/*级别2*//*x*/0,/*y*/28},	{/*级别3*//*x*/0,/*y*/21,/*级别3*//*x*/1,/*y*/28},	{/*级别4*//*x*/1,/*y*/21,/*级别4*//*x*/0,/*y*/22}},
  {/*建业 */	{/*级别1*//*x*/169,/*y*/128,/*级别1*//*x*/170,/*y*/128},	{/*级别2*//*x*/171,/*y*/127,/*级别2*//*x*/172,/*y*/127},	{/*级别3*//*x*/172,/*y*/128,/*级别3*//*x*/172,/*y*/129},	{/*级别4*//*x*/167,/*y*/128,/*级别4*//*x*/168,/*y*/128}},
  {/*吴 */	{/*级别1*//*x*/189,/*y*/138,/*级别1*//*x*/189,/*y*/139},	{/*级别2*//*x*/189,/*y*/140,/*级别2*//*x*/189,/*y*/141},	{/*级别3*//*x*/188,/*y*/138,/*级别3*//*x*/188,/*y*/139},	{/*级别4*//*x*/188,/*y*/140,/*级别4*//*x*/188,/*y*/141}},
  {/*建安 */	{/*级别1*//*x*/149,/*y*/170,/*级别1*//*x*/149,/*y*/171},	{/*级别2*//*x*/149,/*y*/172,/*级别2*//*x*/149,/*y*/173},	{/*级别3*//*x*/149,/*y*/174,/*级别3*//*x*/148,/*y*/172},	{/*级别4*//*x*/148,/*y*/173,/*级别4*//*x*/148,/*y*/174}},
  {/*庐江 */	{/*级别1*//*x*/140,/*y*/119,/*级别1*//*x*/141,/*y*/119},	{/*级别2*//*x*/141,/*y*/120,/*级别2*//*x*/141,/*y*/121},	{/*级别3*//*x*/136,/*y*/120,/*级别3*//*x*/137,/*y*/120},	{/*级别4*//*x*/138,/*y*/121,/*级别4*//*x*/139,/*y*/121}},
  {/*柴桑 */	{/*级别1*//*x*/110,/*y*/140,/*级别1*//*x*/110,/*y*/141},	{/*级别2*//*x*/110,/*y*/142,/*级别2*//*x*/111,/*y*/142},	{/*级别3*//*x*/110,/*y*/143,/*级别3*//*x*/115,/*y*/138},	{/*级别4*//*x*/115,/*y*/139,/*级别4*//*x*/115,/*y*/140}},
  {/*江夏 */	{/*级别1*//*x*/102,/*y*/114,/*级别1*//*x*/103,/*y*/114},	{/*级别2*//*x*/105,/*y*/117,/*级别2*//*x*/104,/*y*/115},	{/*级别3*//*x*/100,/*y*/116,/*级别3*//*x*/105,/*y*/116},	{/*级别4*//*x*/102,/*y*/117,/*级别4*//*x*/103,/*y*/117}},
  {/*云中 */	{/*级别1*//*x*/86,/*y*/8,/*级别1*//*x*/86,/*y*/9},	{/*级别2*//*x*/86,/*y*/10,/*级别2*//*x*/84,/*y*/6},	{/*级别3*//*x*/83,/*y*/5,/*级别3*//*x*/87,/*y*/7},	{/*级别4*//*x*/87,/*y*/8,/*级别4*//*x*/87,/*y*/9}},
  {/*襄阳 */	{/*级别1*//*x*/74,/*y*/125,/*级别1*//*x*/71,/*y*/121},	{/*级别2*//*x*/71,/*y*/122,/*级别2*//*x*/71,/*y*/123},	{/*级别3*//*x*/71,/*y*/124,/*级别3*//*x*/72,/*y*/120},	{/*级别4*//*x*/72,/*y*/125,/*级别4*//*x*/73,/*y*/125}},
  {/*江陵 */	{/*级别1*//*x*/83,/*y*/141,/*级别1*//*x*/83,/*y*/142},	{/*级别2*//*x*/85,/*y*/141,/*级别2*//*x*/85,/*y*/142},	{/*级别3*//*x*/84,/*y*/142,/*级别3*//*x*/84,/*y*/143},	{/*级别4*//*x*/82,/*y*/140,/*级别4*//*x*/82,/*y*/141}},
  {/*长沙 */	{/*级别1*//*x*/107,/*y*/153,/*级别1*//*x*/107,/*y*/154},	{/*级别2*//*x*/107,/*y*/155,/*级别2*//*x*/107,/*y*/156},	{/*级别3*//*x*/106,/*y*/153,/*级别3*//*x*/106,/*y*/154},	{/*级别4*//*x*/107,/*y*/157,/*级别4*//*x*/106,/*y*/155}},
  {/*武陵 */	{/*级别1*//*x*/55,/*y*/153,/*级别1*//*x*/55,/*y*/154},	{/*级别2*//*x*/55,/*y*/155,/*级别2*//*x*/55,/*y*/156},	{/*级别3*//*x*/55,/*y*/157,/*级别3*//*x*/55,/*y*/158},	{/*级别4*//*x*/55,/*y*/159,/*级别4*//*x*/55,/*y*/160}},
  {/*河东 */	{/*级别1*//*x*/69,/*y*/50,/*级别1*//*x*/69,/*y*/51},	{/*级别2*//*x*/69,/*y*/52,/*级别2*//*x*/69,/*y*/53},	{/*级别3*//*x*/68,/*y*/50,/*级别3*//*x*/68,/*y*/51},	{/*级别4*//*x*/68,/*y*/52,/*级别4*//*x*/68,/*y*/53}},
  {/*合浦 */	{/*级别1*//*x*/72,/*y*/199,/*级别1*//*x*/74,/*y*/199},	{/*级别2*//*x*/70,/*y*/199,/*级别2*//*x*/71,/*y*/197},	{/*级别3*//*x*/76,/*y*/197,/*级别3*//*x*/76,/*y*/198},	{/*级别4*//*x*/76,/*y*/199,/*级别4*//*x*/70,/*y*/197}},
  {/*巴东 */	{/*级别1*//*x*/38,/*y*/124,/*级别1*//*x*/39,/*y*/124},	{/*级别2*//*x*/40,/*y*/124,/*级别2*//*x*/41,/*y*/124},	{/*级别3*//*x*/41,/*y*/123,/*级别3*//*x*/42,/*y*/123},	{/*级别4*//*x*/42,/*y*/124,/*级别4*//*x*/43,/*y*/122}},
  {/*汉中 */	{/*级别1*//*x*/29,/*y*/92,/*级别1*//*x*/20,/*y*/93},	{/*级别2*//*x*/19,/*y*/92,/*级别2*//*x*/21,/*y*/92},	{/*级别3*//*x*/19,/*y*/91,/*级别3*//*x*/20,/*y*/92},	{/*级别4*//*x*/20,/*y*/91,/*级别4*//*x*/21,/*y*/91}},
  {/*梓潼 */	{/*级别1*//*x*/12,/*y*/108,/*级别1*//*x*/12,/*y*/107},	{/*级别2*//*x*/11,/*y*/107,/*级别2*//*x*/10,/*y*/108},	{/*级别3*//*x*/9,/*y*/108,/*级别3*//*x*/8,/*y*/109},	{/*级别4*//*x*/8,/*y*/110,/*级别4*//*x*/9,/*y*/111}},
  {/*巴郡 */	{/*级别1*//*x*/36,/*y*/146,/*级别1*//*x*/37,/*y*/151},	{/*级别2*//*x*/36,/*y*/151,/*级别2*//*x*/35,/*y*/150},	{/*级别3*//*x*/35,/*y*/149,/*级别3*//*x*/35,/*y*/148},	{/*级别4*//*x*/35,/*y*/147,/*级别4*//*x*/35,/*y*/146}},
  {/*成都 */	{/*级别1*//*x*/2,/*y*/139,/*级别1*//*x*/2,/*y*/140},	{/*级别2*//*x*/2,/*y*/141,/*级别2*//*x*/2,/*y*/142},	{/*级别3*//*x*/2,/*y*/143,/*级别3*//*x*/2,/*y*/144},	{/*级别4*//*x*/2,/*y*/145,/*级别4*//*x*/2,/*y*/146}},
  {/*南海*/	{/*级别1*//*x*/127,/*y*/191,/*级别1*//*x*/127,/*y*/192},	{/*级别2*//*x*/127,/*y*/193,/*级别2*//*x*/127,/*y*/194},	{/*级别3*//*x*/127,/*y*/195,/*级别3*//*x*/128,/*y*/192},	{/*级别4*//*x*/128,/*y*/193,/*级别4*//*x*/128,/*y*/194}},
  {/*云南 */	{/*级别1*//*x*/15,/*y*/194,/*级别1*//*x*/14,/*y*/194},	{/*级别2*//*x*/14,/*y*/195,/*级别2*//*x*/13,/*y*/196},	{/*级别3*//*x*/13,/*y*/195,/*级别3*//*x*/13,/*y*/194},	{/*级别4*//*x*/12,/*y*/196,/*级别4*//*x*/12,/*y*/195}},

	};

	const array<array<array<int>>> 内政用地升级2 = {
		{/*襄平*/ {/*级别1*/ /*x*/ 194, /*y*/ 30, /*级别1*/ /*x*/ 194, /*y*/ 31}, {/*级别2*/ /*x*/ 191, /*y*/ 17, /*级别2*/ /*x*/ 192, /*y*/ 17}, {/*级别3*/ /*x*/ 199, /*y*/ 9, /*级别3*/ /*x*/ 199, /*y*/ 10}, {/*级别4*/ /*x*/ 178, /*y*/ 7, /*级别4*/ /*x*/ 178, /*y*/ 8}},
		{/*北平*/ {/*级别1*/ /*x*/ 155, /*y*/ 12, /*级别1*/ /*x*/ 155, /*y*/ 13}, {/*级别2*/ /*x*/ 156, /*y*/ 0, /*级别2*/ /*x*/ 157, /*y*/ 0}, {/*级别3*/ /*x*/ 149, /*y*/ 7, /*级别3*/ /*x*/ 149, /*y*/ 8}, {/*级别4*/ /*x*/ 152, /*y*/ 13, /*级别4*/ /*x*/ 152, /*y*/ 14}},
		{/*蓟*/ {/*级别1*/ /*x*/ 125, /*y*/ 14, /*级别1*/ /*x*/ 125, /*y*/ 15}, {/*级别2*/ /*x*/ 125, /*y*/ 16, /*级别2*/ /*x*/ 125, /*y*/ 17}, {/*级别3*/ /*x*/ 131, /*y*/ 21, /*级别3*/ /*x*/ 131, /*y*/ 22}, {/*级别4*/ /*x*/ 132, /*y*/ 22, /*级别4*/ /*x*/ 132, /*y*/ 23}},
		{/*南皮*/ {/*级别1*/ /*x*/ 117, /*y*/ 30, /*级别1*/ /*x*/ 117, /*y*/ 31}, {/*级别2*/ /*x*/ 106, /*y*/ 40, /*级别2*/ /*x*/ 106, /*y*/ 41}, {/*级别3*/ /*x*/ 105, /*y*/ 40, /*级别3*/ /*x*/ 105, /*y*/ 41}, {/*级别4*/ /*x*/ 107, /*y*/ 39, /*级别4*/ /*x*/ 107, /*y*/ 40}},
		{/*平原*/ {/*级别1*/ /*x*/ 139, /*y*/ 33, /*级别1*/ /*x*/ 142, /*y*/ 35}, {/*级别2*/ /*x*/ 130, /*y*/ 42, /*级别2*/ /*x*/ 129, /*y*/ 43}, {/*级别3*/ /*x*/ 128, /*y*/ 41, /*级别3*/ /*x*/ 128, /*y*/ 42}, {/*级别4*/ /*x*/ 129, /*y*/ 41, /*级别4*/ /*x*/ 129, /*y*/ 42}},
		{/*晋阳*/ {/*级别1*/ /*x*/ 83, /*y*/ 18, /*级别1*/ /*x*/ 83, /*y*/ 19}, {/*级别2*/ /*x*/ 93, /*y*/ 30, /*级别2*/ /*x*/ 90, /*y*/ 27}, {/*级别3*/ /*x*/ 83, /*y*/ 24, /*级别3*/ /*x*/ 83, /*y*/ 25}, {/*级别4*/ /*x*/ 84, /*y*/ 24, /*级别4*/ /*x*/ 84, /*y*/ 25}},
		{/*邺*/ {/*级别1*/ /*x*/ 113, /*y*/ 44, /*级别1*/ /*x*/ 114, /*y*/ 44}, {/*级别2*/ /*x*/ 112, /*y*/ 45, /*级别2*/ /*x*/ 111, /*y*/ 45}, {/*级别3*/ /*x*/ 102, /*y*/ 59, /*级别3*/ /*x*/ 103, /*y*/ 59}, {/*级别4*/ /*x*/ 104, /*y*/ 60, /*级别4*/ /*x*/ 105, /*y*/ 59}},
		{/*北海*/ {/*级别1*/ /*x*/ 156, /*y*/ 56, /*级别1*/ /*x*/ 156, /*y*/ 57}, {/*级别2*/ /*x*/ 153, /*y*/ 57, /*级别2*/ /*x*/ 153, /*y*/ 58}, {/*级别3*/ /*x*/ 159, /*y*/ 50, /*级别3*/ /*x*/ 160, /*y*/ 50}, {/*级别4*/ /*x*/ 157, /*y*/ 55, /*级别4*/ /*x*/ 157, /*y*/ 56}},
		{/*下邳*/ {/*级别1*/ /*x*/ 163, /*y*/ 72, /*级别1*/ /*x*/ 163, /*y*/ 71}, {/*级别2*/ /*x*/ 162, /*y*/ 71, /*级别2*/ /*x*/ 162, /*y*/ 70}, {/*级别3*/ /*x*/ 162, /*y*/ 69, /*级别3*/ /*x*/ 163, /*y*/ 69}, {/*级别4*/ /*x*/ 162, /*y*/ 68, /*级别4*/ /*x*/ 163, /*y*/ 68}},
		{/*彭城*/ {/*级别1*/ /*x*/ 136, /*y*/ 82, /*级别1*/ /*x*/ 136, /*y*/ 83}, {/*级别2*/ /*x*/ 138, /*y*/ 72, /*级别2*/ /*x*/ 139, /*y*/ 71}, {/*级别3*/ /*x*/ 140, /*y*/ 71, /*级别3*/ /*x*/ 141, /*y*/ 69}, {/*级别4*/ /*x*/ 142, /*y*/ 70, /*级别4*/ /*x*/ 135, /*y*/ 82}},
		{/*淮南*/ {/*级别1*/ /*x*/ 141, /*y*/ 100, /*级别1*/ /*x*/ 141, /*y*/ 101}, {/*级别2*/ /*x*/ 142, /*y*/ 100, /*级别2*/ /*x*/ 142, /*y*/ 101}, {/*级别3*/ /*x*/ 126, /*y*/ 103, /*级别3*/ /*x*/ 126, /*y*/ 104}, {/*级别4*/ /*x*/ 140, /*y*/ 101, /*级别4*/ /*x*/ 140, /*y*/ 102}},
		{/*濮阳*/ {/*级别1*/ /*x*/ 109, /*y*/ 70, /*级别1*/ /*x*/ 109, /*y*/ 71}, {/*级别2*/ /*x*/ 111, /*y*/ 71, /*级别2*/ /*x*/ 111, /*y*/ 72}, {/*级别3*/ /*x*/ 108, /*y*/ 71, /*级别3*/ /*x*/ 108, /*y*/ 72}, {/*级别4*/ /*x*/ 128, /*y*/ 71, /*级别4*/ /*x*/ 128, /*y*/ 72}},
		{/*陈留*/ {/*级别1*/ /*x*/ 106, /*y*/ 83, /*级别1*/ /*x*/ 106, /*y*/ 84}, {/*级别2*/ /*x*/ 107, /*y*/ 83, /*级别2*/ /*x*/ 107, /*y*/ 84}, {/*级别3*/ /*x*/ 106, /*y*/ 86, /*级别3*/ /*x*/ 106, /*y*/ 85}, {/*级别4*/ /*x*/ 103, /*y*/ 84, /*级别4*/ /*x*/ 103, /*y*/ 83}},
		{/*许昌*/ {/*级别1*/ /*x*/ 102, /*y*/ 88, /*级别1*/ /*x*/ 103, /*y*/ 88}, {/*级别2*/ /*x*/ 104, /*y*/ 88, /*级别2*/ /*x*/ 104, /*y*/ 89}, {/*级别3*/ /*x*/ 103, /*y*/ 87, /*级别3*/ /*x*/ 105, /*y*/ 88}, {/*级别4*/ /*x*/ 102, /*y*/ 89, /*级别4*/ /*x*/ 103, /*y*/ 89}},
		{/*汝南*/ {/*级别1*/ /*x*/ 120, /*y*/ 96, /*级别1*/ /*x*/ 120, /*y*/ 97}, {/*级别2*/ /*x*/ 119, /*y*/ 98, /*级别2*/ /*x*/ 120, /*y*/ 98}, {/*级别3*/ /*x*/ 121, /*y*/ 96, /*级别3*/ /*x*/ 121, /*y*/ 97}, {/*级别4*/ /*x*/ 121, /*y*/ 98, /*级别4*/ /*x*/ 119, /*y*/ 99}},
		{/*洛阳*/ {/*级别1*/ /*x*/ 73, /*y*/ 79, /*级别1*/ /*x*/ 75, /*y*/ 80}, {/*级别2*/ /*x*/ 75, /*y*/ 73, /*级别2*/ /*x*/ 75, /*y*/ 74}, {/*级别3*/ /*x*/ 84, /*y*/ 71, /*级别3*/ /*x*/ 84, /*y*/ 72}, {/*级别4*/ /*x*/ 82, /*y*/ 73, /*级别4*/ /*x*/ 83, /*y*/ 72}},
		{/*宛*/ {/*级别1*/ /*x*/ 71, /*y*/ 95, /*级别1*/ /*x*/ 71, /*y*/ 96}, {/*级别2*/ /*x*/ 87, /*y*/ 94, /*级别2*/ /*x*/ 87, /*y*/ 95}, {/*级别3*/ /*x*/ 73, /*y*/ 101, /*级别3*/ /*x*/ 73, /*y*/ 102}, {/*级别4*/ /*x*/ 74, /*y*/ 102, /*级别4*/ /*x*/ 74, /*y*/ 103}},
		{/*长安*/ {/*级别1*/ /*x*/ 50, /*y*/ 69, /*级别1*/ /*x*/ 51, /*y*/ 69}, {/*级别2*/ /*x*/ 52, /*y*/ 70, /*级别2*/ /*x*/ 53, /*y*/ 70}, {/*级别3*/ /*x*/ 53, /*y*/ 68, /*级别3*/ /*x*/ 53, /*y*/ 69}, {/*级别4*/ /*x*/ 42, /*y*/ 70, /*级别4*/ /*x*/ 42, /*y*/ 71}},
		{/*广陵*/ {/*级别1*/ /*x*/ 184, /*y*/ 88, /*级别1*/ /*x*/ 184, /*y*/ 89}, {/*级别2*/ /*x*/ 179, /*y*/ 87, /*级别2*/ /*x*/ 180, /*y*/ 87}, {/*级别3*/ /*x*/ 163, /*y*/ 87, /*级别3*/ /*x*/ 163, /*y*/ 86}, {/*级别4*/ /*x*/ 164, /*y*/ 87, /*级别4*/ /*x*/ 164, /*y*/ 86}},
		{/*安定*/ {/*级别1*/ /*x*/ 32, /*y*/ 43, /*级别1*/ /*x*/ 31, /*y*/ 44}, {/*级别2*/ /*x*/ 25, /*y*/ 37, /*级别2*/ /*x*/ 26, /*y*/ 37}, {/*级别3*/ /*x*/ 43, /*y*/ 44, /*级别3*/ /*x*/ 42, /*y*/ 43}, {/*级别4*/ /*x*/ 42, /*y*/ 42, /*级别4*/ /*x*/ 44, /*y*/ 45}},
		{/*陇西*/ {/*级别1*/ /*x*/ 4, /*y*/ 63, /*级别1*/ /*x*/ 4, /*y*/ 64}, {/*级别2*/ /*x*/ 4, /*y*/ 65, /*级别2*/ /*x*/ 4, /*y*/ 66}, {/*级别3*/ /*x*/ 15, /*y*/ 67, /*级别3*/ /*x*/ 16, /*y*/ 68}, {/*级别4*/ /*x*/ 14, /*y*/ 75, /*级别4*/ /*x*/ 15, /*y*/ 74}},
		{/*武威*/ {/*级别1*/ /*x*/ 6, /*y*/ 37, /*级别1*/ /*x*/ 6, /*y*/ 38}, {/*级别2*/ /*x*/ 1, /*y*/ 21, /*级别2*/ /*x*/ 1, /*y*/ 22}, {/*级别3*/ /*x*/ 2, /*y*/ 22, /*级别3*/ /*x*/ 3, /*y*/ 22}, {/*级别4*/ /*x*/ 1, /*y*/ 23, /*级别4*/ /*x*/ 2, /*y*/ 23}},
		{/*建业*/ {/*级别1*/ /*x*/ 171, /*y*/ 102, /*级别1*/ /*x*/ 172, /*y*/ 102}, {/*级别2*/ /*x*/ 167, /*y*/ 104, /*级别2*/ /*x*/ 167, /*y*/ 109}, {/*级别3*/ /*x*/ 172, /*y*/ 103, /*级别3*/ /*x*/ 173, /*y*/ 103}, {/*级别4*/ /*x*/ 173, /*y*/ 102, /*级别4*/ /*x*/ 174, /*y*/ 103}},
		{/*吴*/ {/*级别1*/ /*x*/ 173, /*y*/ 114, /*级别1*/ /*x*/ 183, /*y*/ 122}, {/*级别2*/ /*x*/ 184, /*y*/ 123, /*级别2*/ /*x*/ 172, /*y*/ 117}, {/*级别3*/ /*x*/ 185, /*y*/ 119, /*级别3*/ /*x*/ 185, /*y*/ 120}, {/*级别4*/ /*x*/ 185, /*y*/ 121, /*级别4*/ /*x*/ 185, /*y*/ 122}},
		{/*建安*/ {/*级别1*/ /*x*/ 151, /*y*/ 167, /*级别1*/ /*x*/ 152, /*y*/ 167}, {/*级别2*/ /*x*/ 142, /*y*/ 167, /*级别2*/ /*x*/ 142, /*y*/ 168}, {/*级别3*/ /*x*/ 141, /*y*/ 167, /*级别3*/ /*x*/ 141, /*y*/ 168}, {/*级别4*/ /*x*/ 141, /*y*/ 169, /*级别4*/ /*x*/ 142, /*y*/ 169}},
		{/*庐江*/ {/*级别1*/ /*x*/ 140, /*y*/ 118, /*级别1*/ /*x*/ 139, /*y*/ 117}, {/*级别2*/ /*x*/ 137, /*y*/ 116, /*级别2*/ /*x*/ 138, /*y*/ 117}, {/*级别3*/ /*x*/ 140, /*y*/ 114, /*级别3*/ /*x*/ 141, /*y*/ 113}, {/*级别4*/ /*x*/ 141, /*y*/ 114, /*级别4*/ /*x*/ 142, /*y*/ 114}},
		{/*柴桑*/ {/*级别1*/ /*x*/ 123, /*y*/ 152, /*级别1*/ /*x*/ 123, /*y*/ 153}, {/*级别2*/ /*x*/ 123, /*y*/ 154, /*级别2*/ /*x*/ 122, /*y*/ 140}, {/*级别3*/ /*x*/ 122, /*y*/ 139, /*级别3*/ /*x*/ 123, /*y*/ 155}, {/*级别4*/ /*x*/ 124, /*y*/ 153, /*级别4*/ /*x*/ 124, /*y*/ 154}},
		{/*江夏*/ {/*级别1*/ /*x*/ 106, /*y*/ 116, /*级别1*/ /*x*/ 108, /*y*/ 115}, {/*级别2*/ /*x*/ 108, /*y*/ 116, /*级别2*/ /*x*/ 100, /*y*/ 120}, {/*级别3*/ /*x*/ 100, /*y*/ 121, /*级别3*/ /*x*/ 100, /*y*/ 122}, {/*级别4*/ /*x*/ 118, /*y*/ 119, /*级别4*/ /*x*/ 118, /*y*/ 120}},
		{/*河东*/ {/*级别1*/ /*x*/ 70, /*y*/ 55, /*级别1*/ /*x*/ 70, /*y*/ 56}, {/*级别2*/ /*x*/ 66, /*y*/ 42, /*级别2*/ /*x*/ 66, /*y*/ 43}, {/*级别3*/ /*x*/ 66, /*y*/ 44, /*级别3*/ /*x*/ 66, /*y*/ 45}, {/*级别4*/ /*x*/ 64, /*y*/ 45, /*级别4*/ /*x*/ 65, /*y*/ 45}},
		{/*襄阳*/ {/*级别1*/ /*x*/ 54, /*y*/ 109, /*级别1*/ /*x*/ 53, /*y*/ 109}, {/*级别2*/ /*x*/ 53, /*y*/ 108, /*级别2*/ /*x*/ 52, /*y*/ 109}, {/*级别3*/ /*x*/ 56, /*y*/ 111, /*级别3*/ /*x*/ 56, /*y*/ 110}, {/*级别4*/ /*x*/ 51, /*y*/ 108, /*级别4*/ /*x*/ 52, /*y*/ 108}},
		{/*江陵*/ {/*级别1*/ /*x*/ 76, /*y*/ 132, /*级别1*/ /*x*/ 76, /*y*/ 133}, {/*级别2*/ /*x*/ 76, /*y*/ 134, /*级别2*/ /*x*/ 84, /*y*/ 132}, {/*级别3*/ /*x*/ 77, /*y*/ 132, /*级别3*/ /*x*/ 77, /*y*/ 133}, {/*级别4*/ /*x*/ 83, /*y*/ 131, /*级别4*/ /*x*/ 83, /*y*/ 132}},
		{/*长沙*/ {/*级别1*/ /*x*/ 107, /*y*/ 152, /*级别1*/ /*x*/ 107, /*y*/ 153}, {/*级别2*/ /*x*/ 107, /*y*/ 154, /*级别2*/ /*x*/ 107, /*y*/ 155}, {/*级别3*/ /*x*/ 107, /*y*/ 156, /*级别3*/ /*x*/ 106, /*y*/ 152}, {/*级别4*/ /*x*/ 106, /*y*/ 153, /*级别4*/ /*x*/ 106, /*y*/ 154}},
		{/*武陵*/ {/*级别1*/ /*x*/ 80, /*y*/ 151, /*级别1*/ /*x*/ 81, /*y*/ 149}, {/*级别2*/ /*x*/ 81, /*y*/ 150, /*级别2*/ /*x*/ 82, /*y*/ 150}, {/*级别3*/ /*x*/ 60, /*y*/ 151, /*级别3*/ /*x*/ 60, /*y*/ 152}, {/*级别4*/ /*x*/ 79, /*y*/ 151, /*级别4*/ /*x*/ 80, /*y*/ 152}},
		{/*桂阳*/ {/*级别1*/ /*x*/ 86, /*y*/ 0, /*级别1*/ /*x*/ 86, /*y*/ 1}, {/*级别2*/ /*x*/ 85, /*y*/ 0, /*级别2*/ /*x*/ 85, /*y*/ 1}, {/*级别3*/ /*x*/ 89, /*y*/ 4, /*级别3*/ /*x*/ 89, /*y*/ 5}, {/*级别4*/ /*x*/ 90, /*y*/ 5, /*级别4*/ /*x*/ 90, /*y*/ 6}},
		{/*零陵*/ {/*级别1*/ /*x*/ 37, /*y*/ 10, /*级别1*/ /*x*/ 37, /*y*/ 11}, {/*级别2*/ /*x*/ 38, /*y*/ 10, /*级别2*/ /*x*/ 38, /*y*/ 11}, {/*级别3*/ /*x*/ 44, /*y*/ 15, /*级别3*/ /*x*/ 44, /*y*/ 16}, {/*级别4*/ /*x*/ 45, /*y*/ 14, /*级别4*/ /*x*/ 45, /*y*/ 15}},
		{/*永安*/ {/*级别1*/ /*x*/ 47, /*y*/ 132, /*级别1*/ /*x*/ 47, /*y*/ 133}, {/*级别2*/ /*x*/ 38, /*y*/ 127, /*级别2*/ /*x*/ 39, /*y*/ 126}, {/*级别3*/ /*x*/ 40, /*y*/ 125, /*级别3*/ /*x*/ 40, /*y*/ 126}, {/*级别4*/ /*x*/ 39, /*y*/ 127, /*级别4*/ /*x*/ 40, /*y*/ 127}},
		{/*汉中*/ {/*级别1*/ /*x*/ 31, /*y*/ 95, /*级别1*/ /*x*/ 32, /*y*/ 94}, {/*级别2*/ /*x*/ 32, /*y*/ 95, /*级别2*/ /*x*/ 32, /*y*/ 96}, {/*级别3*/ /*x*/ 30, /*y*/ 93, /*级别3*/ /*x*/ 31, /*y*/ 92}, {/*级别4*/ /*x*/ 25, /*y*/ 85, /*级别4*/ /*x*/ 24, /*y*/ 86}},
		{/*梓潼*/ {/*级别1*/ /*x*/ 11, /*y*/ 110, /*级别1*/ /*x*/ 11, /*y*/ 111}, {/*级别2*/ /*x*/ 11, /*y*/ 108, /*级别2*/ /*x*/ 11, /*y*/ 109}, {/*级别3*/ /*x*/ 15, /*y*/ 103, /*级别3*/ /*x*/ 15, /*y*/ 104}, {/*级别4*/ /*x*/ 11, /*y*/ 112, /*级别4*/ /*x*/ 12, /*y*/ 112}},
		{/*江州*/ {/*级别1*/ /*x*/ 35, /*y*/ 146, /*级别1*/ /*x*/ 35, /*y*/ 147}, {/*级别2*/ /*x*/ 35, /*y*/ 148, /*级别2*/ /*x*/ 35, /*y*/ 149}, {/*级别3*/ /*x*/ 23, /*y*/ 140, /*级别3*/ /*x*/ 24, /*y*/ 141}, {/*级别4*/ /*x*/ 23, /*y*/ 138, /*级别4*/ /*x*/ 23, /*y*/ 139}},
		{/*成都*/ {/*级别1*/ /*x*/ 3, /*y*/ 137, /*级别1*/ /*x*/ 3, /*y*/ 138}, {/*级别2*/ /*x*/ 13, /*y*/ 125, /*级别2*/ /*x*/ 13, /*y*/ 126}, {/*级别3*/ /*x*/ 13, /*y*/ 127, /*级别3*/ /*x*/ 12, /*y*/ 125}, {/*级别4*/ /*x*/ 12, /*y*/ 126, /*级别4*/ /*x*/ 12, /*y*/ 127}},
		{/*南中*/ {/*级别1*/ /*x*/ 34, /*y*/ 168, /*级别1*/ /*x*/ 34, /*y*/ 170}, {/*级别2*/ /*x*/ 34, /*y*/ 171, /*级别2*/ /*x*/ 34, /*y*/ 172}, {/*级别3*/ /*x*/ 19, /*y*/ 174, /*级别3*/ /*x*/ 19, /*y*/ 175}, {/*级别4*/ /*x*/ 18, /*y*/ 173, /*级别4*/ /*x*/ 19, /*y*/ 173}},
		{/*合浦*/ {/*级别1*/ /*x*/ 86, /*y*/ 198, /*级别1*/ /*x*/ 86, /*y*/ 199}, {/*级别2*/ /*x*/ 75, /*y*/ 190, /*级别2*/ /*x*/ 75, /*y*/ 191}, {/*级别3*/ /*x*/ 87, /*y*/ 197, /*级别3*/ /*x*/ 87, /*y*/ 198}, {/*级别4*/ /*x*/ 88, /*y*/ 198, /*级别4*/ /*x*/ 88, /*y*/ 199}}

	};
} // namespace end
